garethhall Posted June 1, 2009 Share Posted June 1, 2009 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(); } } Quote Link to comment Share on other sites More sharing options...
bibby Posted June 1, 2009 Share Posted June 1, 2009 "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. Quote Link to comment Share on other sites More sharing options...
garethhall Posted June 2, 2009 Author Share Posted June 2, 2009 Thank you Yes my button was called submit Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.