?
Solved

Java script form validation

Posted on 2012-08-20
8
Medium Priority
?
361 Views
Last Modified: 2012-08-22
The code below shows my simple java  form field validation script.
I would like to add a function that checks for the selection of a check box.
Can anyone assist?
<script type='text/javascript'>
function finalCheck(){
	// Make quick references to our fields
	var ship_dest = document.getElementById('ship_dest');
	// Check each input in the order that it appears in the form!
	if(madeSelection(ship_dest, "Please select a destination")){			
							return true;
					}		
	return false;
}
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}
function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}
</script>

Open in new window

0
Comment
Question by:Neil_Bradley
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Evan Cutler
ID: 38314859
I would need your HTML to see how you localized your combobox.....

that being said:
This article is a good resource:
http://www.webdevelopersnotes.com/tips/html/finding_the_value_of_a_checkbox.php3
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 38315036
Hi arcee123.
Here is the working form. http://gromit.utopia.co.nz/~ballochd/test.php
As you will see I need to add validation to the checkbox.
Thanks,
N
0
 
LVL 7

Expert Comment

by:dimmergeek
ID: 38316026
if (document.getElementById("termsCheck").checked==false)
{
     alert(helperMsg);
     return false;
}

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:Neil_Bradley
ID: 38318117
This is the code source I am using however there is no example of validating a select button.
http://www.tizag.com/javascriptT/javascriptform.php..

dimmergeeek, thanks for your posting however I am unsure how your script fits into my form.
N
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 38318187
Try this.
I think I am on the right track here but its not quite there yet.
http://www.ballochdaleestate.co.nz/test2.php
0
 
LVL 7

Accepted Solution

by:
dimmergeek earned 2000 total points
ID: 38320221
try "if elem.checked==false"
0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 38322517
Thats got it.
Cheers for the assist.
Neil
0
 
LVL 7

Expert Comment

by:dimmergeek
ID: 38322549
You're welcome!
Thanks for the points!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question