PDA

View Full Version : Drop down menu failed to validate



devil_vin
09-23-2007, 03:58 PM
Hi..guys.I have a static display drop down menu,however it doesn't go through the validation function when option is not selected.Thanks for your generious help...



<script language="JavaScript" type="text/JavaScript">
function formSubmit(ticket)
{
var returnStatus = 1;

returnStatus = 0;
if (ticket.rNumber.selectedIndex == 0) {
alert("Please select number of ticket!");
};

if (returnStatus) {
window.location='home.php'
}
}
</script>




<select name="rNumber" id="select4">
<option selected>Select</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
</select>




<form action="" method="post"
name="movieList" id="movieList">
.......
.......
.......
<input name="request" type="submit" id="request" value="Submit Request" onclick="formSubmit(document.movieList)">

Trinithis
09-23-2007, 04:18 PM
use <script type="text/javascript"> instead of your javascript tag.

devil_vin
09-23-2007, 04:29 PM
Thanks for reply,problem resolved.Actually the <form>tag was placed wrongly.However,when mixed with another dynamic radio button written in PHP,the validation of radio button become failed.




<script language="JavaScript" type="text/JavaScript">
function formSubmit(ticket)
{
var returnStatus = 1;

if (ticket.rNumber.selectedIndex == 0){
alert("Please select number of ticket!");
returnStatus = 0;
};
else if( !(movieList.time[<?php echo $rows['name']; ?>].checked)){
alert("Please choose screening time!");
returnStatus = 0;
};
else if (returnStatus) {
window.location='home.php';
};
}
</script>






<?
if (isset($_SESSION['gmemberid'])) {

$tbl_name = "movie";
$result = mysql_query(sprintf('SELECT name,classification,screeningTime FROM %s
LIMIT 7', $tbl_name)) or die('Cannot execute query.');


//$numrow = mysql_num_rows($result);


while ($rows = mysql_fetch_assoc($result)) {
echo '<table width="100%" border="0"><tr><td height="68">
<table width="100%" height="47" border="0">
---------------------------------------------------------------------------------------------------------<br>';

echo '<strong>' . $rows['name'] . ' (' . $rows['classification'] . ')
<br></strong>';
foreach (explode(',', $rows['screeningTime']) as $time) { ?>
<label>
<input type="radio" name="time[<?php echo $rows['name']; ?>]"
value="<?php echo $time; ?>">
<?php echo $time; ?>&nbsp;&nbsp;&nbsp;
</label>
<?php } ?>
<?
}


}
?>





<form action="" method="post" name="movieList" id="movieList">
.......
.......
<input name="request" type="submit" id="request" value="Submit Request" onclick="formSubmit(document.movieList)">