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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.