By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Validation of drop down menu and radio from dynamic display form

P: 22
Hi anybody. I am newbie here and would like to know that how can I validate both drop down menu and radio button from a dynamic display form.Something went wrong with my script.The radio button is dynamic,however drop down menu is static.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/JavaScript">
  2. function formSubmit(obj)
  3. {
  4.     var returnStatus = 1;
  5.  
  6.     if (obj.rNumber.selectedIndex == 0 || 
  7.         !(movieList.time[<?php echo $rows['name'];?>].checked)) { 
  8.         alert("Please select!");
  9.         returnStatus = 0;
  10.     };
  11.  
  12.   }
  13. </script>
  14.  
  15.  
[PHP]
<?
if (isset($_SESSION['gmemberid'])) {

$tbl_name = "movie";
$result = mysql_query(sprintf('SELECT name,category,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['category'] . ')
<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 } ?>
<?
}


}
?>

[/PHP]

[HTML]
<input name="request" type="submit" id="request" value="Submit Request" onClick="formSubmit(document.movieList)">
[/HTML]
Sep 23 '07 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
Hi vinceboy. Welcome to The Scripts!

I don't see any code for a dropdown menu. The code for the radio buttons looks ok tho.

One minor concern tho.
You use explode() on a the data returned by your database. As a rule, no field in you database should contain more than one piece of data. This is the first (1NF) of three rules you should always keep in mind when designing a database. You can read more about them in this article: Normalisation and Table structures .
Sep 23 '07 #2

P: 22
The drop down menu is static display
[HTML]
<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>
[/HTML]

At this moment, I need to know whether any what went wrong at that validation while PHP mix up with Javascript.Thanks for your generious help
Sep 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.