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 06-14-2007, 02:46 PM How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I have some code that validates the form fields. FYI, this is at http://willmaster.com/possibilities/...eldsCheck.html

Once it is done validating, I want it to submit the form. I am not sure how to make it submit it!
//This adds alerts if the form fields are not filled in
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
//This is what happens when the form fields are filled in properly
if(errormessage.length < 2) {
//I want this to submit the form, but I don't know the code
}
What do I put in the code above? submitform() is not working, which is what I have in there now. Please help!

Thanks in advance,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-14-2007, 02:49 PM Re: How to submit form using Javascript?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
document.yourformnamehere.submit() .
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-14-2007, 03:18 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I have tried that
if(errormessage.length < 2) {
document.exampleform.submit();
}

But it doesn't submit, and then status bar says "Error on Page!"
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 05:47 PM Re: How to submit form using Javascript?
ColdFusion's Avatar
Extreme Talker

Posts: 224
Location: NY
Trades: 1
Please post all your code
__________________

Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
*
Please login or register to view this content. Registration is FREE
ColdFusion is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 05:52 PM Re: How to submit form using Javascript?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Or a page where the error occurs.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-14-2007, 06:36 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
The code is here. There is no error message, the form just simply does not submit when you have filled in all of the fields properly. You can do a "view source" on the page below to get all the code.

http://willmaster.com/possibilities/...eldsCheck.html

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-14-2007, 06:40 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Also, my code is below, with my attempt to show where I think I might be able to submit the form (see the green code). It shows the alert but I don't know the code to submit it.


WebGrrl

-----------------------

<html>
<head>




<!-- Beginning of JavaScript for checking required fields and for checking that certain fields contain only digits. -->

<script type="text/javascript" language="JavaScript">
<!-- Copyright 2003 Bontrager Connection, LLC
// Code obtained from http://WillMaster.com/
//
// Each required form field can be checked with JavaScript. Here are
// the function names for the different kinds of checks:
//
// 1. WithoutContent() -- check if the text, textarea, password,
// or file fields has no content.
// 2. NoneWithContent() -- check if none of the set of text,
// textarea, password, or file fields have content.
// (Set: More than one with the same field name.)
//
// 3. NoneWithCheck() -- check if none of the set of radio buttons
// or checkboxes are checked. (Set: More than one with the
// same field name.)
// 4. WithoutCheck() -- check if the single radio button or checkbox
// is unchecked.
//
// 5. WithoutSelectionValue() -- check if selected drop-down list or
// select box entries have no value.
//
//
// The format for using the above functions is
// if( WithoutContent([FORMFIELDVALUE])) [ERRORMESSAGE]
// if( NoneWithContent([FORMFIELD]) ) [ERRORMESSAGE]
// if( NoneWithCheck([FORMFIELD]) ) [ERRORMESSAGE]
// if( WithoutCheck([FORMFIELD]) ) [ERRORMESSAGE]
// if(WithoutSelectionValue([FORMFIELD]) ) [ERRORMESSAGE]
//
// The if(...) part and the error message part may be on separate lines, like
// if(WithoutContent([FORMFIELDVALUE]))
// [ERRORMESSAGE]
// if(NoneWithContent([FORMFIELD]))
// [ERRORMESSAGE]
// if(NoneWithCheck([FORMFIELD]))
// [ERRORMESSAGE]
// if(WithoutCheck([FORMFIELD]))
// [ERRORMESSAGE]
// if(WithoutSelectionValue([FORMFIELD]))
// [ERRORMESSAGE]
//
//
// FORMFIELD -- The format for specifying a "form field" is
// document.[FORMNAME].[FIELDNAME]
// FORMFIELDVALUE -- The format for specifying a "form field value" is
// document.[FORMNAME].[FIELDNAME].value
// ERRORMESSAGE -- The format for specifying an "error message" is
// { errormessage += "\n\n[MESSAGE]"; }
// If the message itself contains quotation marks,
// they must be preceded with a back slash.
// Example: \"
//
//
// FORMNAME -- The name assigned to the form in the <FORM... tag.
// FIELDNAME -- The field name being checked.
//
//
// For use with this JavaScript, the only non-alphanumeric character a
// fieldname may have is the underscore. Replace any hyphens, colons,
// spaces, or other non-alphanumeric characters in your field names
// with an underscore character.
//
//
// Put field checks into the function CheckRequiredFields(), in the order
// you want the fields checked.
//


function CheckRequiredFields() {
var errormessage = new String();
// Put field checks below this point.

if(NoneWithCheck(document.exampleform.projecttype) )
{ errormessage += "\n\nPlease click one radio button of the set of two, Res or Com."; }
if(NoneWithCheck(document.exampleform.radioOne))
{ errormessage += "\n\nPlease click one radio button of the set of three."; }
if(WithoutCheck(document.exampleform.radioLoner))
{ errormessage += "\n\nThe \"Loner\" radio button must be clicked."; }
if(NoneWithCheck(document.exampleform.checkOne))
{ errormessage += "\n\nPlease check one or more check boxes of the set of three."; }
if(WithoutCheck(document.exampleform.checkLoner))
{ errormessage += "\n\nThe \"Loner\" check box must be checked."; }
if(WithoutContent(document.exampleform.sometext.va lue))
{ errormessage += "\n\nPlease type something in the \"Some text\" text field."; }
if(NoneWithContent(document.exampleform.oneOrTheOt her))
{ errormessage += "\n\nSomething must be typed in one or both of the set of form text fields."; }
if(WithoutContent(document.exampleform.areaName.va lue))
{ errormessage += "\n\nSomething must be typed in the textarea box."; }
if(WithoutContent(document.exampleform.FileGet.val ue))
{ errormessage += "\n\nA file name must be provided for uploading."; }
if(WithoutSelectionValue(document.exampleform.drop name))
{ errormessage += "\n\nPlease select something from the dropdown list."; }

// Put field checks above this point.
if(errormessage.length > 2) {
alert('NOTE:' + errormessage);
return false;
}
if(errormessage.length < 2) {
alert('You have succceded! This is where it should submit the form, but I dont know the code yet.');
}
return true;
} // end of function CheckRequiredFields()



function WithoutContent(ss) {
if(ss.length > 0) { return false; }
return true;
}

function NoneWithContent(ss) {
for(var i = 0; i < ss.length; i++) {
if(ss[i].value.length > 0) { return false; }
}
return true;
}

function NoneWithCheck(ss) {
for(var i = 0; i < ss.length; i++) {
if(ss[i].checked) { return false; }
}
return true;
}

function WithoutCheck(ss) {
if(ss.checked) { return false; }
return true;
}

function WithoutSelectionValue(ss) {
for(var i = 0; i < ss.length; i++) {
if(ss[i].selected) {
if(ss[i].value.length) { return false; }
}
}
return true;
}

//-->
</script>






</head>

<body bgcolor="#FFFFFF">
<div align="center">





<!--
1. The form must have a name specified in the <FORM.. tag. This example has name="exampleform"
2. The <FORM.. tag must also have the attribute: onSubmit="return CheckRequiredFields()"
3. You provide the correct method="..." and action="..." FORM tag attributes.
-->
<form name="exampleform" onSubmit="return CheckRequiredFields()" action="http://www.rocklin.ca.us/ASP_Output/Fee_Estimator/project_range.asp" method=post>
<BR><TABLE cellSpacing=2 cellPadding=2 border=1><TBODY>
<TR><TD><LABEL for=RES><INPUT id=RES tabIndex=1 type=radio value=Residential name=projecttype><FONT face=Tahoma size=2> Residential</FONT></LABEL></TD></TR>
<TR><TD><LABEL for=COM><INPUT id=COM tabIndex=2 type=radio value=Commercial name=projecttype><FONT face=Tahoma size=2> Commercial</FONT></LABEL></TD></TR></TBODY>
</TABLE>

<table border="1" cellpadding="9" cellspacing="0"><tr><td>

<input type="radio" name="radioOne" value="one">One<br>
<input type="radio" name="radioOne" value="two">Two<br>
<input type="radio" name="radioOne" value="three">Three
<hr width="33%">
<input type="radio" name="radioLoner" value="RRRR">Loner

</td><td>

<input type="checkbox" name="checkOne" value="one">checkOne one<br>
<input type="checkbox" name="checkOne" value="two">checkOne two<br>
<input type="checkbox" name="checkOne" value="three">checkOne three
<hr width="33%">
<input type="checkbox" name="checkLoner" value="CCCC">Loner

</td></tr><tr><td>

Some text:<br>
<input type="text" name="sometext">
<hr width="33%">
Some text in either or both:<br>
<input type="text" name="oneOrTheOther"><br>
<input type="text" name="oneOrTheOther">

</td><td>

Type something:<br>
<textarea cols="22" rows="5" name="areaName"></textarea>

</td></tr><tr><td>

<input type="file" name="FileGet" size="22">

</td><td>

<select name="dropname">
<option value="">-- Select --</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>


</td></tr><tr><td colspan="2" align="center">

<input type="submit">

</td></tr></table>

</form>


</div>
</body>
</html>
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-17-2007, 05:33 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Any ideas? Please help! Thank you.

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-19-2007, 09:42 PM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
The easiest answer return true; in the function when the form is filled correctly. If it returns true, the form is submitted normally.

If still no luck, I'll actually check over the code, but that's all I noticed from the first post.

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.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 06-25-2007, 08:39 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I tried putting document.exampleform.submit() after return true; but that did not do it. I have tried so many things...I am just not familiar with Javascript syntax...

The original code is below, and it is self-contained, so when you a view source you get the whole code.

http://willmaster.com/possibilities/...eldsCheck.html

Please let me know how to make this form submit...that would rock my world.

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-25-2007, 09:15 PM Re: How to submit form using Javascript?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I tried putting document.exampleform.submit() after return true;
That cannot work.

When a function returns a value, it exit the function at the same time.
Any commands placed after a return will be ignored.

You must either place your form submit command outside of the function (after you have catched the function result) or inside the function, but before the return statement.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-25-2007, 09:21 PM Re: How to submit form using Javascript?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
you where just 1 step of the solution, look:

Code:
// Put field checks above this point.
if(errormessage.length >= 2) {
  alert('NOTE:' + errormessage);
  return false;
	}
else{
  document.exampleform.submit();
  return true;
}
That way, your function should be okay, but it will be tied to a specific form name.

I suggest you rather this:
Code:
function CheckRequiredFields(){
   ... do your checks here ...
    if(errormessage.length >= 2) {
     alert('NOTE:' + errormessage);
     return false;
    	}
   else{
      return true;
   }
}

var chkResult=CheckRequiredFields();
if(chkResult==true){
  document.exempleForm.submit();
}
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-26-2007, 04:00 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
The logic makes sense. I tried it - when you all of the fields are filled out properly the URL shows up in the status bar, but the form does not actually go to the page. Also, even when you first load the page, the status bar says there are "errors on page."

Here is a working example.

Please help....

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-26-2007, 05:25 PM Re: How to submit form using Javascript?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, in my FireFox, it goes ok.
I'm landing on Yahoo.com after submit.

In ie7, on the other hands, it looks like the method of access document.formName.fieldName is deprecated.
At least, editing your file on my comp locally shows that behavior.
Your functions will need to be rewrote and using the dom to achive this.

Maybe it's working on ie6, but I don't have any to test.
Anyone ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 06-26-2007, 07:19 PM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
As I said if the validation returns true it submits the form.

What you need is to tell the form is where to submit it, usually to a processing script which will then process the information of your form. The processing script would be pointed to by the form's action.

Code:
if(errormessage.length < 2)
This part of the code is not the opposite of what you want, the opposite would be to check whether there's nothing in errormessage, rather than check if it has less than 2 characters. However the way the script is set up, if for any reason it does have errors, it will automatically return false, so anything after the script:

Code:
if(errormessage.length > 2)
Should be the part that returns true, which in the original script it does, there's no need for another check, all you need to do is:

Code:
//... What other things you'd like to happen
return true; // this will submit the form to the form's action
If there's errors on the page, it's possible that some methods/properties you use are not correct or not understood by the browser in question.

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; 06-26-2007 at 11:57 PM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 06-27-2007, 03:00 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Thank you for all of the advice, it is interesting that it works in Firefox but not in IE7. I need to work in all recent browsers, and since I am not familar with Javascript syntax, I don't really want to tackle re-writing this code to be up-to-date (not depreciated).

Maybe I should find some other code that will do the job? In my forms, I need to make sure that "if a checkboz is checked, then the text area needs to be filled out." Any suggestions?

There must be something better than what I was trying...

Thanks,

Last edited by webgrrl; 06-27-2007 at 03:11 PM..
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 06-28-2007, 04:08 AM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
If you can provide just the form, it'd be easier to write the script for that.

When you say text area do you mean the textarea element or you mean text inputs?

Say for instance, if I wanted someone to fill in their address if they checked a box saying they wanted information.

I could disable the textarea with javascript so that unless they checked to say they wanted information they could then fill out their address, otherwise there's no point in allowing it. When they check it, I want it to focus on the address textarea so they can fill it out too, without needing an additional click to go inside the textarea. When submitting, I'll check whether the checkbox is checked or not, if checked, I'll see if there's anything in the textarea though only a basic check on string length, so anything more than 2 characters will pass this. We could work on better means of checking but that's entirely up to you if you feel the need to get that far into it.

The code could simply be (working example):

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>HTML Form with basic javascript validation</title>
		<script type="text/javascript">
		// <![CDATA[
		// disables textarea at start, enables it when checkbox is checked
		function toggleAddress() {
			var accept = document.getElementById('accept').checked;
			var address = document.getElementById('address');
			address.disabled ? address.disabled = false : address.disabled = true;
			if(accept) {
				address.focus();
			}
		}
		// ensures the checkbox is unchecked at start and page refresh
		function clearCheck() {
			document.getElementById('accept').checked = false;
		}
		// validates the form to see if checkbox is pressed and whether they filled out the mailing list
		// won't submit if checkbox is checked and there's no address
		// will submit if checkbox isn't checked
		function checkForm() {
			var errormessage = '';
			var accept = document.getElementById('accept').checked;
			if(accept) {
				var address = document.getElementsByTagName('textarea')[0];
				if(address.value.length > 2) {
					return true;
				}
				else {
					alert("A mailing address must be supplied if you want a catalogue.");
					return false;
				}
			}
			return true;
		}
		// ]]>
		</script>
	</head>
	<body onload="toggleAddress(); clearCheck();">
		<form action="?formsent=1" method="post" onsubmit="return checkForm()">
			<fieldset>
				<legend>Basic HTML Form</legend>
				<ul>
					<li><label for="accept">Would you like a catalogue sent to you? Yes</label> <input id="accept" name="accept" type="checkbox" onchange="toggleAddress();"/></li>
					<li><label for="address">Mailing Address:</label> <textarea id="address" rows="5" cols="50"></textarea></li>
				</ul>
				<input id="send" name="send" type="submit" value="Send!" />
			</fieldset>
		</form>
	</body>
</html>
Tested and verified it works in IE7 and FF2, I don't have IE6 to test.

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; 06-28-2007 at 04:44 AM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 06-28-2007, 03:37 PM Re: How to submit form using Javascript?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
*smile* This is working very well! *sigh* of relief...

Yes, actually I need text inputs, not text areas.

I like the disable feature, but I notice that after you sucessfully submit, and then hit the "back button on your browser" the text field is still disabled, even after you hit "refresh" on your browser the text is still disabled. Is there a way to make it so that the text field is enabled whenever the checkbox is checked?

Here is a form. The idea: If you check the checkbox, then you must enter a numeric valuation (where one is required). The last three checkboxes on the form require a valuation (the first three do not require a valuation).



Code:
<FORM name=ProjectFocus action=estimate.asp method=post>
<FIELDSET><LEGEND>I want to do...</LEGEND>
<TABLE cellpadding="4" cellspacing="0">
<TR><TD colspan="2"><LABEL for=ELEC"><INPUT TYPE="checkbox" id=ELEC tabIndex=1 NAME=ProjectFocus0 VALUE="Electrical_Service_Upgrade"><FONT face=Tahoma size=2> Electrical Service Upgrade</FONT></LABEL></TD></TR>
<TR><TD colspan="2" bgcolor="#eeeeee"><LABEL for=HEAT"><INPUT TYPE="checkbox" id=HEAT tabIndex=2 NAME=ProjectFocus1 VALUE="HVAC_Replacement"><FONT face=Tahoma size=2> Heating, Ventilation & Air Conditioning Replacement (like for like)</FONT></LABEL></TD></TR>
<TR><TD colspan="2"><LABEL for=WATER"><INPUT TYPE="checkbox" id=WATER tabIndex=3 NAME=ProjectFocus2 VALUE="Water_Heater_Replacement"><FONT face=Tahoma size=2> Water Heater Replacement (like for like)</FONT></LABEL></TD></TR>
<TR><TD colspan="2">&nbsp;</TD></TR>
<TR><TD colspan="2" bgcolor="#eeeeee"><LABEL for=WINDOW"><INPUT TYPE="checkbox" id=WINDOW tabIndex=4 NAME=ProjectFocus3 VALUE="Window_Replacement"><FONT face=Tahoma size=2> Window Replacement (enlargement, reduction and/or new windows)</FONT></LABEL></TD></TR>
<TR><TD width="30%" bgcolor="#eeeeee"></TD><TD bgcolor="#eeeeee"><FONT face=Tahoma size=2>Enter Valuation:&nbsp;</FONT><input type=text id=WINDOWVALUATION tabIndex=5 name=Window_Replacement_Valuation></TD></TR>
<TR><TD colspan="2">
<LABEL for=REFOOF"><INPUT TYPE="checkbox" id=REROOF tabIndex=6 NAME=ProjectFocus4 VALUE="Re_Roofing"><FONT face=Tahoma size=2> Re-Roofing</FONT></LABEL></TD></TR>
<TR><TD></TD><TD><LABEL for=REROOFMAT><FONT face=Tahoma size=2>Re-Roofing Materials</FONT></LABEL>
<SELECT id=REROOFMAT tabIndex=7 NAME="Re_Roofing_Materials" SIZE="1">
<OPTION value="ReHYPHENRoofing_CompositeFSLASHShake"><FONT face=Tahoma size=2>Composite/Shake</FONT>
<OPTION value="ReHYPHENRoofing_MetalFSLASHTile"><FONT face=Tahoma size=2>Metal/Tile</FONT>
</SELECT></TD></TR>
<TR><TD></TD><TD><FONT face=Tahoma size=2>Enter Valuation:&nbsp;</FONT><input type=text id=REROOFVALUATION tabIndex=8 name=Re_Roofing_Valuation></TD></TR>

<TR><TD colspan="2" bgcolor="#eeeeee"><LABEL for=RESIDE"><INPUT TYPE="checkbox" id=RESIDE tabIndex=9 NAME=ProjectFocus5 VALUE="Re_Siding"><FONT face=Tahoma size=2> Re-Siding</FONT></LABEL></TD></TR>
<TR><TD bgcolor="#eeeeee"></TD><TD bgcolor="#eeeeee"><FONT face=Tahoma size=2>Enter Valuation:&nbsp;</FONT><input type=text id=RESIDEVALUATION tabIndex=9 name=Re_Siding_Valuation></TD></TR>
</TABLE>
</FIELDSET>
</FORM>
You are awesome...

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 07-05-2007, 05:07 AM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Hey WebGrrl,

I haven't forgotten about this, just been a bit busy lately, thanks for bringing up that problem with IE, I've added a small solution for it (quick fix really), but it wasn't apparent in FF at all.

I'll start working on this form and come up with the solution later.

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.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 07-05-2007, 06:47 AM Re: How to submit form using Javascript?
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
OK here's a do-hickory hack of the above form, not the idealist way to go about it but I rushed it.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-NZ">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>HTML Form with basic javascript validation</title>
		<script type="text/javascript">
		// <![CDATA[
		function init() {
			var inputs = document.getElementsByTagName('input');
			for(i in inputs) {
				switch(inputs[i].type) {
					case 'checkbox':
						inputs[i].checked = false;
						break;
					case 'text':
						inputs[i].disabled = true;
						break
					default:
						break;
				}
			}
		}
		function enableInput(el) {
			document.getElementById(el.id + 'valuation').disabled = (document.getElementById(el.id + 'valuation').disabled) ? false : true;
		}
		function validateForm() {
			var errormsg = '';
			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(errormsg.length < 2) {
				return true;
			}
			alert(errormsg);
			return false;
		}
		// ]]>
		</script>
	</head>
	<body onload="init();">
		<form action="?estimate=1" method="post" onsubmit="return validateForm();">
			<fieldset>
				<legend>I want to do&hellip;</legend>
				<ul>
					<li><input id="elec" name="ProjectFocus0" tabindex="1" value="Electrical_Service_Upgrade" type="checkbox" /> <label for="elec">Electrical Service Upgrade</label></li>
					<li><input id="heat" name="ProjectFocus1" tabindex="2" value="HVAC_Replacement" type="checkbox" /> <label for="heat">Heating, Ventilation &amp; Air Conditioning Replacement (of similar type)</label></li>
					<li><input id="water" name="ProjectFocus2" tabindex="3" value="Water_Heater_Replacement" type="checkbox" /> <label for="water">Water Heater Replacement (of similar type)</label></li>
					<li><input id="window" name="ProjectFocus3" tabindex="4" value="Window_Replacement" type="checkbox" onchange="enableInput(this);" /> <label for="window">Window Replacement (enlargement, reduction and/or new windows)</label></li>
					<li><label for="windowvaluation">Window valuation:</label> <input id="windowvaluation" name="Window_Replacement_Valuation" tabindex="5" type="text" /></li>
					<li><input id="reroof" name="ProjectFocus4" tabindex="6" value="Re_Roofing" type="checkbox" onchange="enableInput(this);" /> <label for="reroof">Re-Roofing</label></li>
					<li><label for="reroofmat">Re-Roofing Materials</label>
						<select id="reroofmat" name="Re_Roofing_Materials" tabindex="7">
							<option label="Composite/Shake" value="ReHYPHENRoofing_CompositeFSLASHShake">Composite/Shake</option>
							<option label="Metal/Tile" value="ReHYPHENRoofing_MetalFSLASHTile">Metal/Tile</option>
						</select></li>
					<li><label for="reroofvaluation">Re-Roof Valuation:</label> <input id="reroofvaluation" name="Re_Roofing_Valuation" tabindex="8" type="text" /></li>
					<li><input id="reside" name="ProjectFocus5" tabindex="9" value="Re_Siding" type="checkbox" onchange="enableInput(this);" /> <label for="reside">Re-Siding</label></li>
					<li><label for="residevaluation">Reside Valuation:</label> <input id="residevaluation" name="Re_Siding_Valuation" tabindex="9" type="text" /></li>
				</ul>
				<input id="send" name="send" value="Send!" type="submit" />
			</fieldset>
		</form>
	</body>
</html>
I could have spent more time cleaning up the script, but this should hopefully help you out.

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-05-2007 at 06:49 AM..
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
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.59631 seconds with 12 queries