I am writing an HTML form. I need the selected value of a <select> tag to then populate an <input type="text" [...] /> tag. I got this to work just fine, but when I wrap the form in a <div id="form">[...]</div> it stops working. I have searched up and down google for an answer, but I am unsure if I even understand how to ask the question!
Here is my sample code as of yet:
So if you remove the id="form" from <div id="form"> it works just fine and gives me an alert.
var myTest = form.select.options[form.select.selectedIndex].value;
<form action="" method="post" name="form">
<span class="title">Add Details</span>
<select name="select" onChange="myTest()">
<option value="this text in alert box">trying</option>
<option value="some other text">something</option>
<option value="value 3">new</option>
How to I reference the <div id=form> to make it work properly?
Do I need to do this for every div the form is in?
Thanks in advance!
Try this code:
Add document in the code.
var myTest = document.form.select.options[document.form.select.selectedIndex].value;
Almost there, a few more questions
Ok, That seams to have worked in my quick crude sample, but doesn't seam to work for the actual page that I am trying this on. Thanks for the help!
I think I understand what that "document.whatever..." line does, but I can't seams to figure it out. I am a long time PHP programmer, but I never understood Java and never really coded it until today. So as you can image, a lot of questions come to mind. Could you maybe explain how that "document.something.form.whatever.value" is structured? What is it called so I can good look it up myself.
I'm sure it's something simple I just don't know what to search for to find my answer!
Thanks again for the help!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)