• 0

Change textbox in iframe from parent


Question

Hey,

Im having a bit of a problem, im trying to update the value in a texbox that is in an iframe. the updated value is coming from the normal page.

<input type="text" name="tb1">
<input type="button">

<iframe>
<input type="text" name="tb2">
</iframe>

I want to take the value in tb1 and put it in tb2 when the user presses the button.

Im still searching the net to see if i can see how to do this, but im hoping that some smart person here will already know :D

Any ideas?

Thanks in advance

Link to comment
https://www.neowin.net/forum/topic/875894-change-textbox-in-iframe-from-parent/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

This can be done using javascript. I would recommend doing this when the form is submitted rather than user click on button. You could also do this when the input looses focus. If you have included jquery framework it can be done with the following code

$('input[name="tb1"]').blur(function(){

val = $(this).attr('value');

$('input[name="tb2"]').attr('value', val);

});

  • 0

Assuming you can give your input elements IDs (they were only named in your example) and that you only have one iframe, this should work.

window.frames[0].document.getElementById('tb2').value = document.getElementById('tb1').value;

And here is a jQuery equivalent, since we're on the subject.

$('iframe:first').contents().find('#tb2').val($('#tb1').val());

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'm not sure why anyone would want to use Chrome on Android when there are far better browsers that let you disable ads. I personally use Vivaldi and never see ads by default. Am I right in thinking you can't block ads on Chrome for Android?
    • Same time next month y'all, when we see this 💩posted again?
    • I mean, it's not like they did something like force you to have U2's "Songs of Innocence" on your computer with no way to remove it... *coughcough*
    • Going to quote myself from a comment I made to a related article: It's not about the OS, it's about the workflow. OS fans consistently miss this. People have work to do and they've invested a lot of time, effort and even money building their workflows. It's expensive to change, so that change has to offer real benefits that compensate for the cost of updating workflow and sorry, Win 11 just doesn't. Win 11 breaks workflow in weird and pointless ways seemingly either to dumb down the OS (with the same results as we saw when MSFT tried to dumb down Office's menuing system with "SmartMenus") or make it look more like macOS. MSFT seems to have completely lost the basics of UI/UX like FITS and muscle memory in Win 11. If they had made these optional - then sure, but they aren't. That's the same reason most users won't just jump to an entirely new OS - which has an even bigger workflow cost - until there's just no other option. Not only is there the core workflow cost, but the cost of finding new parallel software for the new OS, transferring and possible converting files and dealing with incompatibilities and then redeveloping workflows. It's just not as simple as "switch". And now there IS another option, stay on Win 10 for another year and pray for Win 12 (much as Win 7 users did with Win 8 - which happened when Win 10 came out).
    • At least that album was really good. I don't know if F1 was $200 million well spent yet...
  • Recent Achievements

    • Mentor
      The Werewolf went up a rank
      Mentor
    • First Post
      Myriachan earned a badge
      First Post
    • Week One Done
      DrRonSr earned a badge
      Week One Done
    • Week One Done
      Sharon dixon earned a badge
      Week One Done
    • Dedicated
      Parallax Abstraction earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      615
    2. 2
      ATLien_0
      227
    3. 3
      +FloatingFatMan
      170
    4. 4
      Michael Scrip
      166
    5. 5
      Som
      148
  • Tell a friend

    Love Neowin? Tell a friend!