Javascript: how to insert value into text input fields from a drop down menu -
I am quite new to javascript, so I hope that someone here can help me with this small task.
I currently have two input text fields, which I need to be populated with text after choosing an option from the drop down menu.
For example ...
I have a selected field that looks like this:
& lt; Select ID = "select_2" onchange = "insertProduct (2);" & Gt;
And in that selection I have options that look like this:
& lt; Option id = "cdrom001" title = "my cdrom" & gt; Cdrom001 - my cdrom & lt; / Option & gt; & Lt; Option id = "DVD-ABUG" title = "life of a bug" & gt; DVD-ABUG - A Bug's Life & lt; / Option & gt; & Lt; Option id = "DVD-BELOVED" title = "dear" & gt; DVD-BELOVED - Furry & lt; / Option & gt; ....
What do I do, when I select an option from that drop down list, then I want my text input field # 1 with option ID Populate (e.g., DDD-AUG) and I want my text input field # 2 to be populated with the option title (such as the life of a bug).
Here is the code for my two text input fields:
I have a lot of writing of this function which will be required to do this ...
function insertProduct (id) {// code here
As you can see, I do not have much: o)
Can someone help me with that function that does this? Could?
Thanks a lot!
Change this line:
To do this:
& lt; Select ID = "select_0" onchange = "insertProduct (this, 0);" & Gt;
and use this function:
function insertProduct (select, line) {var model = "model_"; Var product = "product_"; Document.getElementById (model + line) .value = select.options [select.selectedIndex] .id; Document.getElementById (Product + line) .value = select.options [select.selectedIndex] .title; }
Comments
Post a Comment