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.

Recommended Answers

All 5 Replies

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>


How do you know which option should be selected for each page load?

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.

Hello Everyone,

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

here s the code


unction setPosit(val)
              var id1=document.getElementById('Sopt');
                for(var i=0;i<id1.options.length;i++)

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.

if your problem is solved then mark the thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.