473,242 Members | 1,442 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,242 software developers and data experts.

How to prevent auto redirect of drop down menu?

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 kind of fast respond?

Expand|Select|Wrap|Line Numbers
  1. <select name="rNumber" title="number of ticket"
  2.                      onChange="GoToNextPage(this.value)">
  3.                       <option selected>Select</option>
  4.                       <option>01</option>
  5.                       <option>02</option>
  6.                       <option>03</option>
  7.                       <option>04</option>
  8.                       <option>05</option>
  9.                       <option>06</option>
  10.  </select>
  11.  
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/JavaScript">
  2.     function validate(which) {
  3.         var selects = which.getElementsByTagName('select');
  4.         var radios = which.getElementsByTagName('input');
  5.         for(sel = 0; sel < selects.length; sel++) {
  6.             if(selects[sel].options[selects[sel].selectedIndex].text == 'Select') {
  7.                 alert('Please select number of ticket!');
  8.                 return false;
  9.             }
  10.         }
  11.  
  12.         var rselCount = 0;
  13.         for(radio = 0; radio < radios.length; radio++) {
  14.             if(radios[radio].checked) {
  15.               rselCount++;
  16.             }
  17.         }
  18.  
  19.         if(rselCount == 0) {
  20.            alert('Please select screening time!');
  21.            return false;
  22.         }
  23.         return true;
  24.     }
  25.  
  26.    function GoToNextPage(value){
  27.         if(value != ""){
  28.        document.location = 'reservation3.php?selected_no_ticket=' + value;
  29.   }
  30. }
  31.  
Expand|Select|Wrap|Line Numbers
  1. <form action="reservation3.php" method="post" name="movieList" 
  2. onSubmit="return validate(this);">
  3.  
And also when onchange mixed with onsubmit,the validation can't execute
alert('Please select screening time!'); when radio button was not selected.What went wrong in the script?Thanks...
Sep 25 '07 #1
11 2605
acoder
16,027 Expert Mod 8TB
GoToNextPage() is sending it to the next page, so just get rid of the onchange.
Sep 25 '07 #2
I can't remove it because need to display the number of ticket in next page.
[PHP]<?= $_GET['selected_no_ticket']; ?>[/PHP]

What I intend to do is capturing the selected value and display it in next page.In the form I have radio button and drop down menu which apply onclick and onchange attribute respectively in a single function.

Expand|Select|Wrap|Line Numbers
  1.  function GoToNextPage(value){
  2.         if(value != ""){
  3.        document.location = 'reservation3.php?selected_no_ticket=' 
  4.        +value+'selected_time=' + value;
  5.   }
  6. }
  7.  

Expand|Select|Wrap|Line Numbers
  1. <form action="reservation3.php" method="post" name="movieList" 
  2.           onSubmit="return validate(this);">
  3.  
  4. <select name="rNumber" title="number of ticket"onChange="GoToNextPage_ticket(this.value)">
  5.  
  6. <input type="radio"  name="time[<?php echo $rows['name']; ?>]"
  7.  title ="screening time" value="<?php echo $time; ?>"
  8. onClick ="GoToNextPage(this.value)">
  9.  
However,by combining them into one GoToNextPage function,validate function can't work at all and the selected value are not displayed in next page.
Sep 25 '07 #3
acoder
16,027 Expert Mod 8TB
Don't use onclick and onchange to pass form values. Let the submit take care of that.

When the form is submitted, the validation function is run. If it validates, return true so the form submits and the values are passed to the next page. If it doesn't validate, return false so the form submission is stopped.
Sep 25 '07 #4
You meant that changed onchange and onclick to onsubmit?
Sep 25 '07 #5
acoder
16,027 Expert Mod 8TB
You meant that changed onchange and onclick to onsubmit?
No, when onsubmit returns true, the values will automatically be passed to the action page. Perhaps, you're accessing the values in the wrong way. You're using POST and in your PHP, you're trying to access with $_GET.
Sep 25 '07 #6
I have changed accessing method to POST,however how can I display both selected value in next page without using GoToNextPage function,onchange and onclick?
$_POST[' ?']
Sep 25 '07 #7
acoder
16,027 Expert Mod 8TB
I have changed accessing method to POST,however how can I display both selected value in next page without using GoToNextPage function,onchange and onclick?
$_POST[' ?']
Yes, you would use $_POST for post-ed form values, but now we're moving into PHP territory.
Sep 25 '07 #8
Can you help me to work out?Thanks for generious help....
Sep 25 '07 #9
acoder
16,027 Expert Mod 8TB
Can you help me to work out?Thanks for generious help....
With the PHP? I direct you to the capable hands of the experts in the PHP forum.Have you solved your original problem?
Sep 25 '07 #10
Solved already,Thanks a lot.Now validation control well but only thing can't display value in next page.
Sep 25 '07 #11
acoder
16,027 Expert Mod 8TB
Solved already,Thanks a lot.Now validation control well but only thing can't display value in next page.
Since it's not Javascript-related, just start a new thread in the PHP forum (if you haven't already done so).

Edit: I see that you have. Well, good luck with the rest of your project.
Sep 25 '07 #12

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...
10
by: Haines Brown | last post by:
I've implemented the horizontal drop down menu discussed recently in this newsgroup, and it works nicely under Galeon and Mozilla, but not IE 5.0. Here are the problems: Under IE 5.0, the...
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...
4
by: jesse.hartwick | last post by:
Hey group! I have a toolbar with a "DEVELOPER" menu. I have it so that it when the menu title is clicked, a pop-up form will appear if the user has not yet verified that he or she has developer...
1
by: gauravtechie | last post by:
Hi all, I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change, the code is <html>...
4
by: magmike | last post by:
I've got a control on my form that allows the user to select a record based on a form field (in this example, the drop down menu shows the company name, followed by the contact name but uses the...
1
by: thetechgeek | last post by:
Hey all, I've created a pretty nice-looking drop-down menu, and I need to prevent users form highlighting the text in the menu item, because it looks kind of ugly. Here's an snippet of my menu...
5
by: totalstranger | last post by:
I'm working on a lightweight, auto width, auto centered, one level drop down menu. It's working in FF, IE7 and Safari (all windows versions on my local system), however it fails in Opera. Can...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.