We help IT Professionals succeed at work.
Get Started

Pass Select Option's Value to a Textbox in Iframe

FrankTech
FrankTech asked
on
1,994 Views
Last Modified: 2012-05-05
On my main page is a select box, that is not in a form (there is no <form> element on the main page):

        <select name="select1" id="select1">
          <option>Select</option>
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
        </select>

That page contains an iframe named "if1" and id="if1".

The iframe contains a textbox (named "textfield" and id="textfield").

The main page and the page in the iframe are both on my own domain.

When the user changes the Select Option, the value should be passed into the textbox in the iframe.

I tried this, but it gives an error ("is null or not an object"):

     <select onChange="window.frames[if1].document.formiframe.textfield.value=this.options[this.selectedIndex].value;">

So how can I reference and pass values to the textbox inside the iframe ?
Main Page:
 
<html>
<body>
  <select name="select1" id="select1" onChange="window.frames[if1].document.form2.textfield.value=this.options[this.selectedIndex].value;">
    <option value="">Choose</option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
  </select>
 
<iframe name="if1" id="if1" src="pageForIframe.php"></iframe>
</body>
</html>
 
 
----------------------
Code of Other Page Inside Iframe:
 
<html>
<head>
<body>
<form name="form2" id="form2" method="post" action="#">
<input type="text" id="textbox" name="textbox">
</form>
</body>
</html>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE