473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Select Box Validation

I am having issues with making sure users select an option from a select
box... here is my code

function checkit(){
if (document.postdata.phonenumber == ""){
alert("Please enter a Phone Number");
return false;}
if (document.postdata.request[document.postdata.request.selectedIndex].value
== ""){
alert("Please Select a Request");
return false;}
}


<form name=postdata action=?action=add method=post onsubmit='return
checkit()'>
<input type=text name=phonenumber>
<select name=request>
<option value=1>Send manual</option>
<option value=2>Duplicate Product</option>
<option value=3>Did not order</option>
</select>
<input type=submit>
</form>

can someone help me figure this out. I believe it is because
document.postdata.request is undefined until an option is chosen but I don't
know how to fix that.

Jul 20 '05 #1
2 22957
Brian

Check for a selectedIndex value of -1. If no item is selected in a
Select object then:
document.formName.selectObjectName.selectedIndex
will return -1.

Hope that helps

Jul 20 '05 #2
Lee
Brian Kramer said:

I am having issues with making sure users select an option from a select
box... here is my code

function checkit(){
if (document.postdata.phonenumber == ""){
alert("Please enter a Phone Number");
return false;}
if (document.postdata.request[document.postdata.request.selectedIndex].value
== ""){
alert("Please Select a Request");
return false;}
}
can someone help me figure this out. I believe it is because
document.postdata.request is undefined until an option is chosen but I don't
know how to fix that.


No, the problem is that the value of selectedIndex is -1 until an option
is chosen. and document.postdata.request[-1].value is undefined.
That should be all you need to know to fix it.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I...
1
by: Griff | last post by:
Hi! I'm using JavaScript on an HTML page for form validation. I have a form value (theForm.ProdType1) which represents a picklist from which users may make multiple selections; essentially,...
7
by: | last post by:
I can't get IE 6 to read the values in my <SELECT..> data entry fields. Netscape 7 and Opera see them, and IE will pass the values to the database, but the javascript validation script gets a null...
4
by: Alonso | last post by:
Hello everybody! :-D I am trying to validate a select object in a form. It does not work fine in Explorer 6.0 because it always send the form, but in Netscape 7.0 it works really fine. The code...
5
by: Tim Johnson | last post by:
Howdy: I'm just learning how to use focus() and select(). I have a very large form (360+ elements). Javascript validation is launched by the 'onclick' event handler in the "submit" button tag....
5
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
0
by: BijuP | last post by:
Hi, I have a datagird having datatable as its datasource. It has a column called "Check" which appears as checkbox in the grid. The user can manually go and click on that field to check/uncheck...
2
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name...
5
by: Bubba | last post by:
I have a dynamic pulldown list (ASP with javascript) that when a user picks a state, the corresponding counties for that state appear in a dynamic second pulldown list. When I submit the form, the...
2
by: Sudhakar | last post by:
i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2 there are different regions for city1 and city2 so instead of all the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.