Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox - Selected Item text 1

Status
Not open for further replies.

vbsuser

Programmer
Jul 14, 2009
3
IN
I need your help with regards to the following.

I have a list box on a page which contains many items and the user can select one item at a time. I would like to get the text of the item selected in the list through VBScript. Is there some property of the listbox that would give me the text of the item selected through VBScript? FYI..method ‘post’ id being used on the page.

Thanks!!
 
You need to set "value" attribute to obtain cross-browser applicability. If it is the "text" you want to pass, put the "text" string as "value" attribute's value.
 
Thanks for the response. I think I could not explain my problem correctly.

Say I have a list box and the user selected an item in the same. Now, through VBScript I want if an Item is selected or not. Is there some way of knowing if an item is selected in the listbox?
 
I am new to vbscript, hence need a little help.

I have a ASP page coded in HTML and VBscript; Javascript is used only for a writing functions that gets called at the events of the controls. The page has a list box and a ‘Add’ button. Add button is disabled.

<input name="Add" type="button" disabled value="Add" onclick="xyz" class="btn1" />

Now, what I need is, if an item is selected in the list box, my Add button should be enabled, else, it should be disabled. On the onchange event of the listbox, I am calling a function say ‘abcd’ that has the code to enable/disabled Add button. But, there is some additional processing written in that function to deal with the database and that additional processing submits this page and calls the same page (kind of refreshes the same page and displays some additional info from DB).

The problem is that the function abcd enables/disables Add button, but when the form is submitted in this function the entire code gets executed again and due to code (<input name="Add" type="button" disabled value="Add" onclick="xyz" class="btn1" />), the button is always disabled.

Please advise how can I check if there is something selected in the listbox just before the above line of code i.e. <input name="Add" type="button" disabled value="Add" onclick="xyz" class="btn1" />
 
You should use a server-side solution. As you said you use post method, suppose
[ol][li] the "listbox" (a select-one element) is named "[blue]selname[/blue]", and[/li]
[li] the option with value "[blue]abc[/blue]" be the one which will make the button enabled, otherwise, disabled[/li][/ol]
then the input button can look like this.
[tt]
<input name="Add" type="button" <% if not (request.form("[blue]selname[/blue]")="[blue]abc[/blue]") then response.write "disabled=""disabled""" %> onclick="xyz" class="btn1" />[/tt]

If you don't get it, ask asp forum for more advice.

ps: I hope xyz be a vbscript function even it is only target to internet-explorer as browser, otherwise, if it is a javascript function, then it must appear at least like "xyz[red]()[/red]" without looking at the detail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top