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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get ListBox Value

Status
Not open for further replies.

tag2007

Technical User
Joined
Aug 23, 2006
Messages
3
Location
GB
Hi All,
Im new to JS and cant get this right as yet.
Im trying to get the value of a list box and just am not getting it...

No matter what I choose in the list Box the else statment gets carried out

The list box had to options to choose and the valies are 4 or 5

Here is what I have:
Code:
var gen=(document.PedigreeForm.txtGenerations.value);

if (gen = 4){return (MyString2);}
else {return (MyString);}

Thanks
Tag
 
What do you mean "listbox"? Do you mean a <select> list?



Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Hi Thanks for replying,
Yes i do indeed mean the Select List sorry I usually work with VB and this is the controls name ..

I have just worked this out and needed to get the selected items index and check it..
This seems to have done it..

Thanks again
Tag

Code:
if (document.MyForm.txtGenerations.selectedIndex !=0){return (MyString);}
else {return (MyString2);}
 
.value, while not my preferred method, should work fine.

the issue you had in your first code snippet is this:

Code:
if (gen =[red]=[/red] 4){return (MyString2);}
else {return (MyString);}

comparison needs two equals signs.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thank you ,
Yes you are correct and I did have to alter the comparison as it was setting the value with what I had eh!!

Its a muddle trying to learn something new at times eh?
You know what you want to say but dont know how to say it...
LOL

Thank you.
Tag
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top