1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Change textarea value from iframe

Discussion in 'JavaScript' started by Axcell, Jun 29, 2016.

  1. #1
    I have 2 files. a.html and b.html. a.html contains iframe with source b.html and 2 textareas (1 wysiwyg textarea and 1 standard textarea. b.html contain 2 buttons, button 1 to change textarea 1 value and button 2 to change textarea 2 value but button 1 not working.
    Please help
    a.html
    <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> <script type="text/javascript">
    bkLib.onDomLoaded(function() {
    new nicEditor({fullPanel : true}).panelInstance('cnt');
    });
    </script>
      Iframe
    <iframe name="ifr" src="b.html" id="ifr" style="width:30%;display:block;"></iframe><br>
    <table>
      <tr>
        <td valign="top">Textarea 1
    <textarea name="cnt" cols="30" rows="20" id="cnt"></textarea></td>
        <td valign="top"> Textarea 2<br>
    <textarea name="cnt2" cols="30" rows="20" id="cnt2"></textarea></td>
      </tr>
    </table>
    
    HTML:
    b.html
    <input type="button" value="texarea 1" onClick="parent.document.getElementById('cnt').value = Math.random() * 100;" />
    <input type="button" value="texarea 2" onClick="parent.document.getElementById('cnt2').value = Math.random() * 100;" />
    HTML:

     
    Axcell, Jun 29, 2016 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    dimes to dollars what's blocking you is the cross site scripting block. Frames are intentionally isolated from each-other and are NOT supposed to be allowed to have access to each-others content. The page in a iframe is NOT EVER supposed to be allowed to access the parent page's content, or vice-versa. It was used, abused, and eventually blocked. Whoever told you that you could do that isn't qualified to be telling you how to do things.

    Now that said - and apologies if this sounds harsh -- to be brutally frank what you've presented for code seems to me to indicate you don't know enough about HTML to be playing around with JavaScript yet. You're really NOT supposed to even be using iframes (as of like... 18 years ago), you've got tables for layout, no label tags, static scripting in the markup instead of having your scripts hook the markup, and likely zero graceful degradation for scripting off.

    You've got a laundry list of broken markup methodology mated to sloppy scripting practices. I'm not certain what it is you expect this mess to accomplish, but I'm pretty sure this isn't how you go about it. Lose the iframe nonsense and go learn some more HTML.
     
    deathshadow, Jun 30, 2016 IP
  3. Axcell

    Axcell Active Member

    Messages:
    128
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    73
    #3
    actualy this is just sample code, the original is too complicated but problem is the same change textarea on parent from hidden iframe. I just create my php ajax script.
     
    Axcell, Jun 30, 2016 IP