Is it required that a defualt value be selected at the time of population as opposed to a later time for a combo box?

StackOverflow https://stackoverflow.com/questions/13768347

  •  05-12-2021
  •  | 
  •  

Question

Using an example I found on the internet:

<select name="Company">
 <option value="08">08</option>
 <option value="09" selected>09</option>
 <option value="33">33</option>
 <option value="18">18</option>
 <option value="17">17</option>
</select>

As you can see, the 2nd element gets default at the time of it's population. Is there a way select the 2nd element as default after listing the values?

<select name="Company">
 <option value="08">08</option>
 <option value="09">09</option>
 <option value="33">33</option>
 <option value="18">18</option>
 <option value="17">17</option>
</select>

<!-- HTML 4 code that selects the 2nd element goes here-->

For the purpose of my environment, it does need to be HTML 4 compliant. I have not been able to find whether or not this is possible or the syntax to accomplish this. There is a server sided procedure that will be producing the HTML that does the selecting at a later point. The server side language is PowerOn, in case you were interested.

Était-ce utile?

La solution

Yes you can, but you can't use HTML for that. You must code some client side language like JavaScript.

<select name="Company" id="Company">
    <option value="08">08</option>
    <option value="09">09</option>
    <option value="33">33</option>
    <option value="18">18</option>
    <option value="17">17</option>
</select>

<script type="text/javascript">
    document.getElementById('Company').value = "09";
</script>

I recommend you to read some JavaScript resources and jQuery too. It will be very useful.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top