adam291086 Posted January 23, 2008 Share Posted January 23, 2008 I have a form validationd script. Instead of an indivdual alert appearing for each question i would like to display the error message above the question. if (!(mainform.question1[0].checked || mainform.question1[1].checked || mainform.question1[2].checked || mainform.question1[3].checked || mainform.question1[4].checked || mainform.question1[5].checked || mainform.question1[6].checked)) { alert ('Please fill out question 1'); event.returnValue=false; } if (mainform.question1[0].checked || mainform.question1[1].checked || mainform.question1[4].checked || mainform.question1[5].checked || mainform.question1[6].checked) { mQ1av=mainform.question1a.value; if (mQ1av=='') { alert ('Please fill out question 1a.'); event.returnValue=false; } } Any help is appreciated as i am a jave noobie Link to comment https://forums.phpfreaks.com/topic/87349-solved-getting-the-error-message-to-display-red-by-the-form-question/ Share on other sites More sharing options...
phpQuestioner Posted January 23, 2008 Share Posted January 23, 2008 you keep saying your a java noobie; but this javascript; it's a different language. also the only way your going to not be a noobie is to try to learn some javascript - that's a good start. change the alert to document.getElementById().innerHTML and add your errors message to it. create a label above/beside (where ever you want the error message to display) your form fields; you will give each label a unique id. when a validation error occurs, the document.getElementById().innerHTML will fill the label with the error message. Link to comment https://forums.phpfreaks.com/topic/87349-solved-getting-the-error-message-to-display-red-by-the-form-question/#findComment-446782 Share on other sites More sharing options...
adam291086 Posted January 23, 2008 Author Share Posted January 23, 2008 sorry, i get confused with the languages i am using. I am learning. I took the code you gave me yesterday and learned how it worked and adapted it for the rest of my Form. So am i looking to do this if (!(mainform.question1[0].checked || mainform.question1[1].checked || mainform.question1[2].checked || mainform.question1[3].checked || mainform.question1[4].checked || mainform.question1[5].checked || mainform.question1[6].checked)) { document.getElementById(Q1).innerHTML="Please fill out question 1"; event.returnValue=false; } Then in the form have something like <label id=Q1></label> 1) In terms of using property derivatives, is your company the <br /> <br /> <input type="radio" onClick="checker1(this.value)" id="Property Company" value="Property Company" name ="question1">Property Company <br /> Link to comment https://forums.phpfreaks.com/topic/87349-solved-getting-the-error-message-to-display-red-by-the-form-question/#findComment-446789 Share on other sites More sharing options...
phpQuestioner Posted January 23, 2008 Share Posted January 23, 2008 yeah man, that should work out the way you want it to - good luck Link to comment https://forums.phpfreaks.com/topic/87349-solved-getting-the-error-message-to-display-red-by-the-form-question/#findComment-446794 Share on other sites More sharing options...
adam291086 Posted January 23, 2008 Author Share Posted January 23, 2008 i have added that into my script. Now non of the validation seems to happen and the form is sent to my email this is what i have form <FORM NAME="mainform" ACTION="http://adamplowman.co.uk/mike/formvalidation.php" METHOD="post" onSubmit="validate();"> <label id=adam></label> 1) In terms of using property derivatives, is your company the <br /> <br /> <input type="radio" onClick="checker1(this.value)" id="Property Company" value="Property Company" name ="question1">Property Company <br /> and validation if (!(mainform.question1[0].checked || mainform.question1[1].checked || mainform.question1[2].checked || mainform.question1[3].checked || mainform.question1[4].checked || mainform.question1[5].checked || mainform.question1[6].checked)) { document.getElementById(adam).innerHTML="Please fill out question 1"; event.returnValue=false; } Link to comment https://forums.phpfreaks.com/topic/87349-solved-getting-the-error-message-to-display-red-by-the-form-question/#findComment-446797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.