Skip to content Skip to sidebar Skip to footer

How To Add Data Into A Text Input And Select Data In A Drop Down Menu?

I have a simple application which yo can see here: application In the application you will see a drop down menu, simply select a course from the drop down menu and you will see the

Solution 1:

Problem 1:

You should find a way to "link" durations to items in the dropdown, so... what you don't want to do (put all in the option tag) looks to be the best answer. Anyway you could write a javascript array and use the 's selectedIndex value to point to the good data, with a thing like that :

$('select').change(function()
{
   var index = this.selectedIndex;
   $('input').val(duration_data[index]);
}

Problem 2:

Same as first, as u said. Use the selectIndex property to set your default value by the code.

$('select')[0].selectedIndex = n

Post a Comment for "How To Add Data Into A Text Input And Select Data In A Drop Down Menu?"