Nick Swan's SharePoint Blog

a day in the life of a Sharepoint and .NET guy!

My Links

News




Post Categories

Archives

Blog Stats

Blogroll

Books

VB-tech website

VB-tech work

Xbox

ASP.NET and JavaScript - getting selected value

I’ve always managed to stay away from too much client side stuff so I’ve been struggling a bit with a few javascript things. Main one today was getting the selected value of drop down list. I wanted to do this as the value of this depended on whether to show a second drop down. Here’s the code to add the onchange event. This links together the DropDownList and the client side javascript code:

ddlCountry.Attributes.Add("onchange", "checkSelectedValue()")

And here’s the actual javascript code itself.

function checkSelectedValue()
{
    if(document.Form1.ddlCountry[document.Form1.ddlCountry.selectedIndex].value < 0) 
    { }
}

Thanks to Ray Booysen for helping me to solve that one!
I’m also having a bit of fun with the Custom Validator Control and a Check Box. I got it working fine for Internet Explorer, but alas in Firefox it doesn’t seem to work. Haven’t searched on Google for this one yet though so haven’t give up! I need a good book on ASP.NET and Javascript. Anyone recommend one?

posted on Friday, March 25, 2005 7:33 PM

Get email alerts when this blog is updated!

Feedback

# re: ASP.NET and JavaScript - getting selected value 5/17/2006 9:22 AM Oguz

should the code like this:

if(document.Form1.ddlCountry.options[document.Form1.ddlCountry.selectedIndex].value < 0)

# re: ASP.NET and JavaScript - getting selected value 9/29/2006 11:01 AM Steve Fenton

You can get the same result in shorthand:

document.Form1.ddlCountry.value

Will in fact return the selected item's value attribute.

Title  
Name  
Url
Comments - All Comments are moderated and will not be displayed until approved by this blog's author    
Enter the code you see: