Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 30th, 2004, 06:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default javascript validation for select option

We can verify if select option are set using isset() in PHP.
Can someone tell similar approach in JavaScript. Please tell.

__________________
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
PHP, SEO | anshul shrivastava | mediasworks.org | FB
  #2 (permalink)  
Old December 30th, 2004, 11:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use the SELECTED property of the Option you are looking at :

document.myForm.mySelect.options[0].selected

is TRUE if the first option in the Dropdown called mySelect on the form called myForm is selected. In the case of a multiple select, then each will be set to true.
  #3 (permalink)  
Old January 4th, 2005, 12:31 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi Anshul
Alternatively we can get
indexval=document.myForm.mySelect.selectedIndex

now you can check which option is selected.
<SCRIPT>
function temp()
{
whichindex=document.testform.firstlst.selectedInde x
if(whichindex>0)
 //option is set
else
 // option is not set
}
</SCRIPT>
<form name="testform">
<select name=firstlst onchange="temp()">
<option value=0>SelectNumber </option>
<option value=1>1 </option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
</form>
Hope this will help you

Cheers :)

vinod


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help putting xsl:value-of in select option eruditionist XSLT 2 September 25th, 2008 08:27 AM
wrap a select option nerssi HTML Code Clinic 0 June 16th, 2007 07:43 AM
disable Select option Dj Kat HTML Code Clinic 2 March 10th, 2006 04:03 AM
Select/Option Problem TSEROOGY Javascript 2 October 4th, 2004 03:32 PM
Getting select option name not value mildge Javascript How-To 2 April 5th, 2004 10:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.