selecting a default option in a drop down list

V

vimal

hi all,

i am still a learner in javascript

i have a select tag with options as follows:

<select>
<option py:for="mb in range(32,100)">${mb}</option>
</select>

which dynamically generates numbers ranging from 32 to 100

and if i want the list to show the value "50" when the page is loaded
what should be done

thanks in advance,
vimal
Binary Karma Enterprise
 
R

RobG

hi all,

i am still a learner in javascript

i have a select tag with options as follows:

<select>
<option py:for="mb in range(32,100)">${mb}</option>
</select>

which dynamically generates numbers ranging from 32 to 100

and if i want the list to show the value "50" when the page is loaded
what should be done

Set the appropriate option element's selected property to true.
 
V

vimal

Set the appropriate option element's selected property to true.

no if we r having a manual entry.....
like
<select> or (.selected="true")-->in javascript
<option>vimal</option>
<option>sanjay</option>
<option selected="selected">ajay</option>
<option>someone</option>
</select>


in this case we know the options
but i want to select the cases i which the options are unknown
that is they r generated dynamically
 
R

RobG

Please don't quote signatures, trim quotes to what you are replying too.
no if we r having a manual entry.....

This is not SMS. Please use reasonable grammar, spelling and punctuation.

like
<select> or (.selected="true")-->in javascript
<option>vimal</option>
<option>sanjay</option>
<option selected="selected">ajay</option>
<option>someone</option>
</select>


in this case we know the options
but i want to select the cases i which the options are unknown
that is they r generated dynamically

If you don't know what option you want to select, it doesn't matter how
you go about doing it, you don't know which one to select.

I guess you need to loop through the existing options and whichever ones
have their selected property set to true, set them to false. Or remove
them.

Then use whatever logic appeals to you to set the selected property of
one or more to true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top