0

hi...anyone got ideas in form validation...I try a lot of methods already but still can't work...do not have any pop-up message although the required fill leave blank...is it the reason that I create my form in separate file??anyone got ideas on how to solve this problem?thanks in advance...

part of the code

class_survey.php

while($row = mysql_fetch_array($result))
{ 
      echo "<td width='50' align='center'>$row[no]</td>";
      echo "<td width='500' align='left'>$row[question]</td>";
      echo "<td align='center' width='500'>               
                <input type='radio' name='rating[$i]' value='1'/>1                <input type='radio' name='rating[$i]' value='2'/>2
                <input type='radio' name='rating[$i]' value='3'/>3
	<input type='radio' name='rating[$i]' value='4'/>4
	<input type='radio' name='rating[$i]' value='5'/>5</td>";
      echo "<td align='center' width='50'><input name='score[$i]' type='text' id='title'size='5' align='middle'></td>"
     echo "<td><textarea name='remark[$i]' cols='25' id='title'></textarea></td>";
     echo "</tr>";
     $i++;
}

surveyForm.php

function validate()
{ 	
if((document.surveyForm.rating[1].checked==false)&& document.surveyForm.rating[2].checked==false)&&(document.surveyForm.rating[3].checked==false))&&(document.surveyForm.rating[4].checked==false) &&(document.surveyForm.rating[5].checked==false&&(document.surveyForm.rating[6].checked==false)&&(document.surveyForm.rating[7].checked==false))
{ 
     alert('Please choose the rating!'); 
     return false 
}
else if (surveyForm.score.value == "")
{
     alert("Please insert mark.");
     surveyForm.score.focus();
     return false;
}
 
else if(surveyForm.remark.value == "")
{
      alert("Please insert remark.");
      surveyForm.remark.focus();
      return false;
}  
   return true;
}

<form name="surveyForm" id="surveyForm" method="post" action="surveyForm2.php" onSubmit="return validate()">
<div align="center"><?php $survey->survey($form); ?></div>
</form>
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by star_lavender
0

Look at the source code for the document in your browser, do the elements have the correct names (the ones you are expecting)?

0

yes...the names are correct...so that means it doesn't matter they are in separate file or in the same file and called the form using object??but they can't work...
I try another method for validate the rating as below...still can't work..

function validate()
{
     for( var i=0;i<=6;i++)
    { 
           if ((!document.rating[1].checked)&&(!document.rating[2].checked)&&(!document.rating[3].checked)&&(!document.rating[4].checked)&&(!document.rating[5].checked)&&(!document.rating[6].checked)&&(!document.rating[7].checked))
         {
              alert("The rating cannot be empty!");
              return false;
        }
}	
	return true;
}

below are the source code for the document in the browser...

<input type='radio' name='rating[1]' value='1'/>1
<input type='radio' name='rating[1]' value='2'/>2
<input type='radio' name='rating[1]' value='3'/>3
<input type='radio' name='rating[1]' value='4'/>4
<input type='radio' name='rating[1]' value='5'/>5

<input type='radio' name='rating[2]' value='1'/>1
<input type='radio' name='rating[2]' value='2'/>2
<input type='radio' name='rating[2]' value='3'/>3
<input type='radio' name='rating[2]' value='4'/>4
<input type='radio' name='rating[2]' value='5'/>5

repeat until ...

<input type='radio' name='rating[7]' value='1'/>1
<input type='radio' name='rating[7]' value='2'/>2
<input type='radio' name='rating[7]' value='3'/>3
<input type='radio' name='rating[7]' value='4'/>4
<input type='radio' name='rating[7]' value='5'/>5

for the score (textbox) and remark (textarea) also same like rating...array...any ideas???

Look at the source code for the document in your browser, do the elements have the correct names (the ones you are expecting)?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.