473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Drop down menu failed to validate

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

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/JavaScript">
  2. function formSubmit(ticket)
  3. {
  4.     var returnStatus = 1;
  5.  
  6.     if (ticket.rNumber.selectedIndex == 0) { 
  7.         alert("Please select number of ticket!");
  8.         returnStatus = 0;
  9.     };
  10.  
  11.     if (returnStatus) { 
  12.         window.location='home.php'
  13.     }
  14. }
  15. </script>
  16.  
Expand|Select|Wrap|Line Numbers
  1. <select name="rNumber" id="select4">
  2.                       <option selected>Select</option>
  3.                       <option>01</option>
  4.                       <option>02</option>
  5.                       <option>03</option>
  6.                       <option>04</option>
  7.                       <option>05</option>
  8.                       <option>06</option>
  9. </select>
  10.  
Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post" 
  2. name="movieList" id="movieList">
  3. .......
  4. .......
  5. .......
  6. <input name="request" type="submit" id="request" value="Submit Request"    onclick="formSubmit(document.movieList)">
  7.  
Sep 23 '07 #1
3 1250
acoder
16,027 Expert Mod 8TB
Use return false after the alert on line 8.

Instead of 0 and 1, consider using a boolean (true/false).

If you just change the location, the form value will not be sent to the next page. Set an action and let the form submit.
Sep 23 '07 #2
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.

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/JavaScript">
  2. function formSubmit(ticket)
  3. {
  4.     var returnStatus = 1;
  5.  
  6.     if (ticket.rNumber.selectedIndex == 0){ 
  7.         alert("Please select number of ticket!");
  8.         returnStatus = 0;
  9.     };
  10.    //if( !(movieList.time[php echo $rows['name'];?>].checked)){
  11.           //alert("Please choose screening time!");
  12.           //returnStatus = 0;
  13.      //};   
  14.     if (returnStatus) { 
  15.         window.location='home.php';
  16.     };
  17. }
  18. </script>
  19.  
  20.  
[PHP]

<?
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 } ?>
<?
}


}
?>

[/PHP]

Expand|Select|Wrap|Line Numbers
  1. <input name="request" type="submit" id="request" value="Submit Request"  onclick="formSubmit(document.movieList)">
  2.  
Sep 23 '07 #3
acoder
16,027 Expert Mod 8TB
To validate a form, use the onsubmit event:
[HTML]<form name="..." action="..." onsubmit="return formSubmit(this);">[/HTML] In formSubmit(), returnValue should be set to true or false. If the validation passes, return true. If it fails, return false.
Sep 24 '07 #4

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

Similar topics

3
by: KK | last post by:
Drop-down menus are the hottest thing since Wonder Bread but . . . 1. Alot of people put them in the they-look-nice-but-you-cant-code-them-right-so-they-always-look-messed-up category (a la...
0
by: vikram.cvk | last post by:
Hello Experts, Im trying to design a CSS vertical drop down menu which should have the following functionality. Home About Us | -->Overview
4
by: simon.cigoj | last post by:
I have an javascript made menu and some forms with the dropdown element. When the menu opens and scrolls down the drop down is displeyed over the menu and obscures the menu choices. I have this...
2
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
2
by: vinceboy | last post by:
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...
11
by: vinceboy | last post by:
Hi..guys!I have a drop down menu with javascript null validation.However,instead of clicking submit button,it will immediately auto redirect after option was selected.Is it possible to prevent this...
0
by: Jack Gray | last post by:
I am using a nested list for a simple drop-down menu. All CSS and XHTML validate. The menu is displayed properly in 7 different newer browsers including IE7, Firefox, Opera & Safari. I have...
0
by: Jack Gray | last post by:
Hi everyone, I am using a nested list for a simple drop-down menu. All CSS and XHTML validate. The menu is displayed properly in 7 different newer browsers including IE7, Firefox, Opera & Safari....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.