Jump to content

[SOLVED] Problems submitting a form


garethhall

Recommended Posts

Hello I don't know why but this javascript is driving me insane! I have only had problems with it from the start. At least the learning curve is and was good.

 

Why is my form not submitting?

 

This is the error I am getting

"document.forms[frmName].submit is not a function"

 

 

And lastly you can see I got send1 send2 and so on How can I call them dynamically interm if the variable name?

So lets say alerting the values if the send[] variable. something like

 

alert(send)  this does not work?

 

Here is my code

function validate(frmName, fieldName, fieldEmail, fieldPhone, apprvMK, rejectMK){
// Set Variables to hold values and followed by Element Name
var name  = document.forms[frmName].elements[fieldName].value;
var nameElementName  = document.forms[frmName].elements[fieldName].name;
var emailAddress  = document.forms[frmName].elements[fieldEmail].value;
var emailElementName  = document.forms[frmName].elements[fieldEmail].name
var phone  = document.forms[frmName].elements[fieldPhone].value;
var phoneElementName  = document.forms[frmName].elements[fieldPhone].name;

// This runs the validation and updates the Page
var i = 0;
var send;
function runValidation(myField, MyReg, MyElementName){i++
	if(!myField.match(MyReg)){
		document.getElementById("spn_"+MyElementName).innerHTML = "<img src='"+rejectMK+"' width='15' height='15' />";
		window['send' + i] = 'false';
	}else{
		document.getElementById("spn_"+MyElementName).innerHTML = "<img src='"+apprvMK+"' width='15' height='15' />";
		window['send' + i] = 'true';
	}
}
runValidation(name, nameReg, nameElementName);
runValidation(emailAddress, emailReg, emailElementName);
runValidation(phone, phoneReg, phoneElementName);

if(send1 == "false" || send2 == "false" || send3 == "false"){
	return false;
}else{
	document.forms[frmName].submit();
}

}

Link to comment
https://forums.phpfreaks.com/topic/160553-solved-problems-submitting-a-form/
Share on other sites

"submit" may not be a function, but is it an object?

 

alert( typeof document.forms[frmName].submit );

 

If it is, then you've probably fallen for an old trick,  naming the submit button "submit"

 

<input type="submit" name="submit" value="submit"/>

  ...  don't do this!

It overrides the native submit method with a reference to the form element.

 

---

RE:

var phoneElementName  = document.forms[frmName].elements[fieldPhone].name;

 

Doesn't phoneElementName == fieldPhone  ?  That seems strange to me.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.