Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to submit form using Javascript?
Old 07-06-2007, 05:40 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
OMG, this code is great, it is just what I need! You rock! The fix for the disable/enable feature is working great, too.

One more thing....

I want to make sure that people check at least one checkbox (in other words, I don't want them to submit the form without filling out anything). Is there a way to see that at least one checkbox is checked?

Thanks in advance,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2007, 06:42 PM Re: How to submit form using Javascript?
Junior Talker

Posts: 2
Name: aChunkyMuttWhoLovesQuotingCheney
Trades: 0
Far as I can see, it works in Safari version 2.0.4.
I get sent to the Yahoo page.
Maybe just dosen't work in DOM enabled browsers?
No idea, really...
chunkymutt is offline
Reply With Quote
View Public Profile
 
Old 07-07-2007, 06:44 PM Re: How to submit form using Javascript?
Junior Talker

Posts: 2
Name: aChunkyMuttWhoLovesQuotingCheney
Trades: 0
Nevermind....
looks like you're good.
chunkymutt is offline
Reply With Quote
View Public Profile
 
Old 07-08-2007, 07:28 PM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Just alter this function to be like:

Code:
function validateForm() {
			var hasCheck = false;
			var errormsg = '';
			var checkboxes = document.getElementsByTagName('input');
			for(a in checkboxes) {
				try {
					if(checkboxes[a].checked) {
						hasCheck = true;
						break;
					}
				}
				catch(e) {
				}
			}
			var inputs = new Array(document.getElementById('window'),document.getElementById('reroof'),document.getElementById('reside'));
			for(i in inputs) {
				if(inputs[i].checked) {
					if((document.getElementById(inputs[i].id + 'valuation').value.length < 2) || isNaN(document.getElementById(inputs[i].id + 'valuation').value)) {
						errormsg += inputs[i].id + ": Requires a valid number of certain length.\n";
					}
				}
			}
			if(!hasCheck) {
				errormsg += "You must at least check one before submitting.\n";
			}
			if(errormsg.length < 2) {
				return true;
			}
			alert(errormsg);
			return false;
		}
That should be it.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.

Last edited by mastercomputers; 07-08-2007 at 07:37 PM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 07-13-2007, 07:41 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Awesome, I will try this out

Thanks a million,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 08-03-2007, 01:53 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
mastercomputers:
The above code works beautifully in IE. It makes sure that
  • 1. A value is associated with any checked checkbox AND
  • 2. At least one checkbox is checked

However, it doesn't seem to do #1 in Netscape and Firefox. Any ideas?

BTW, the first version of this code (meant to do only #1) DOES work in Netscape and Firefox, interestingly enough, so it looks like both concepts can work, I just need them to work for Netscape & Firefox in the same chunk of code. Can you help? That would be really awesome...

Thank you in advance,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to submit form using Javascript?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16623 seconds with 11 queries