0

Hello Everyone,

I have a problem and looking forward for your kind help.
I need the <select> tags option value to be set selected on the page load.
The problem is that everytime the value which is to be selected may change on each page load.

Thank you.

4
Contributors
5
Replies
20
Views
4 Years
Discussion Span
Last Post by IIM
0

You need to add your logic that will define which option must be selected, then you set it to selected like this:

<select name="mySelect">
    <option value="1">First Option</option>
    <option value="2" selected>Second Option</option>
</select>
0

i think so you are referring to make 2 linked drop down.So for that you have to make ajax call and then it will work fine.

0

Hello Everyone,

Thank you so much for your reply and suggestions. Somehow I managed to fix the problem.

here s the code

f

unction setPosit(val)
            {
              var id1=document.getElementById('Sopt');
                for(var i=0;i<id1.options.length;i++)
                    {
                        if(id1.options[i].value===val)
                            {
                                id1.selectedIndex=i;
                                break;
                            }
                    }
           }

Im sending the value which was selected previously as the argument "val" and im iterating between the entire list of options available. mean while im checking whether there is a match between the value passed and the value of the option. if there is a match then that particular option will be set as selected.

Thank you.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.