Tuesday, May 15, 2012

Java Script - Validation for Empty Textbox with php


Java Script - Validation for Empty Textbox with php


<script type="text/javascript">
// Validation for Empty Textbox 
function validateForm()
{
var question=document.forms["quizForm"]["question"].value;
var option1=document.forms["quizForm"]["optn1"].value;
var option2=document.forms["quizForm"]["optn2"].value;
var option3=document.forms["quizForm"]["optn3"].value;
var option4=document.forms["quizForm"]["optn4"].value;
var correctanswer=document.forms["quizForm"]["answer"].value;
var explaination=document.forms["quizForm"]["explain"].value;
var references=document.forms["quizForm"]["ref"].value;
var keyword=document.forms["quizForm"]["key"].value;


if ((question==null || question=="") ||
(option1==null || option1=="" ) ||
(option2==null || option2=="" ) ||
(option3==null || option3=="" ) ||
(option4==null || option4=="" ) ||
(correctanswer==null || correctanswer=="" ) ||
(explaination==null || explaination=="" ) ||
(references==null || references=="" ) ||
(keyword==null || keyword=="" ) )
  {
  alert("All fields must be filled out");
  return false;
  }
 }
 </script>

 <body>


 <form id="form_406085" name="quizForm" class="appnitro"  method="post" action="quiz_input1.php" onsubmit="return validateForm()">
<div class="form_description">
<h2>Quiz - Learn Concept Daily (LCD)</h2>
<p>Learn Concept Daily (LCD)</p>
</div>
<ul >

<li id="li_8" >
<label class="description" for="question">Question :</label>
<div>
<textarea id="question" name="question" class="element textarea small"></textarea> 
</div> 
</li> <li id="li_10" >
<label class="description" for="optn1">Option 1: </label>
<div>
<input id="optn1" name="optn1" class="element text small" type="text" maxlength="255" value=""/> 
</div> 
</li> <li id="li_11" >
<label class="description" for="optn2">Option 2: </label>
<div>
<input id="optn2" name="optn2" class="element text small" type="text" maxlength="255" value=""/> 
</div> 
</li> <li id="li_12" >
<label class="description" for="optn3">Option 3: </label>
<div>
<input id="optn3" name="optn3" class="element text small" type="text" maxlength="255" value=""/> 
</div> 
</li> <li id="li_13" >
<label class="description" for="optn4">Option 4: </label>
<div>
<input id="optn4" name="optn4" class="element text small" type="text" maxlength="255" value=""/> 
</div> 
</li> <li id="li_7" >
<label class="description" for="answer">Correct Answer :</label>
<div>
<input id="answer" name="answer" class="element text medium" type="text" maxlength="255" value=""/> 
</div> 
</li> <li id="li_4" >
<label class="description" for="explain">Explaination :</label>
<div>
<textarea id="explain" name="explain" class="element textarea medium"></textarea> 
</div> 
</li> <li id="li_5" >
<label class="description" for="ref">References :</label>
<div>
<input id="ref" name="ref" class="element text medium" type="text" maxlength="255" value=""/> 
</div>
</li> <li id="li_6" >
<label class="description" for="key">Google Keywords  :</label>
<div>
<input id="key" name="key" class="element text medium" type="text" maxlength="255" value=""/> 

</div> 
</li>
 </body>

No comments:

Post a Comment