I am in need of assistance with a JavaScript task as I am still relatively new to it.
Currently, I have two input text fields that I would like to populate with text based on the selection made from a dropdown menu.
For instance...
The select field looks like this:
<select id="select_2" onchange="insertProduct(2);">
And the options within the select field appear as follows:
<option id="cdrom001" title="my cdrom">cdrom001 - my cdrom</option>
<option id="DVD-ABUG" title="A Bug's Life">DVD-ABUG - A Bug's Life</option>
<option id="DVD-BELOVED" title="Beloved">DVD-BELOVED - Beloved</option>
....
What I am aiming for is that upon selecting an option from the dropdown list, text input field #1 should be filled with the option id (e.g. DVD-ABUG) and text input field #2 should be populated with the option title (e.g. A Bug's Life).
Here is the code for the two text input fields:
<input type="text" name="model[]" id="model_2">
<input type="text" name="product[]" id="product_2">
I have begun writing the function that will be necessary for this task, but I need help:
function insertProduct(id){
// code goes here
}
As you can tell, I haven't made much progress. :o)
Could someone provide guidance on how to create the function for this task?
Thank you so much!