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

Link to comment
Share on other sites

 

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
Share on other sites

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
Share on other sites

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