Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > selecting a default option in a drop down list

Reply
Thread Tools

selecting a default option in a drop down list

 
 
vimal
Guest
Posts: n/a
 
      10-04-2007
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 9:53 pm, vimal <(E-Mail Removed)> wrote:
> 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.


--
Rob

 
Reply With Quote
 
 
 
 
vimal
Guest
Posts: n/a
 
      10-04-2007
On Oct 4, 5:31 pm, RobG <(E-Mail Removed)> wrote:
> On Oct 4, 9:53 pm, vimal <(E-Mail Removed)> wrote:
>
> > 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.
>
> --
> Rob


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

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-04-2007
vimal wrote:
> On Oct 4, 5:31 pm, RobG <(E-Mail Removed)> wrote:
>> On Oct 4, 9:53 pm, vimal <(E-Mail Removed)> wrote:
>>
>>> 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.
>>
>> --
>> Rob


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.



--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
retrive preselected value in second drop down list from the first drop down list weiwei ASP .Net 0 01-05-2007 07:29 PM
Selecting an item in a drop down list KatMagic ASP .Net 3 04-11-2006 07:25 PM
Auto Drop down a Drop Down List xxbmichae1@supergambler.com Javascript 5 11-23-2005 01:35 AM
Re: Selecting an item in a drop down list Natty Gur ASP .Net 1 08-18-2003 02:40 PM
Selecting an item in a drop down list Bogdan Zamfir ASP .Net 2 08-17-2003 10:06 PM



Advertisments