Jump to content

[SOLVED] Getting the error message to display red by the form question


adam291086

Recommended Posts

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

 

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.

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

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;

}

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.