Results 1 to 2 of 2

Thread: How to prevent auto redirect of drop down menu?

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Code:
    <select name="rNumber" title="number of ticket"
    					 onChange="GoToNextPage(this.value)">
                          <option selected>Select</option>
                          <option>01</option>
                          <option>02</option>
                          <option>03</option>
                          <option>04</option>
                          <option>05</option>
                          <option>06</option>
     </select>
    Code:
    <script language="JavaScript" type="text/JavaScript">
        function validate(which) {
            var selects = which.getElementsByTagName('select');
            var radios = which.getElementsByTagName('input');
            for(sel = 0; sel < selects.length; sel++) {
                if(selects[sel].options[selects[sel].selectedIndex].text == 'Select') {
                    alert('Please select number of ticket!');
                    return false;
                }
            }
    
            var rselCount = 0;
            for(radio = 0; radio < radios.length; radio++) {
                if(radios[radio].checked) {
                  rselCount++;
                }
            }
    
            if(rselCount == 0) {
               alert('Please select screening time!');
               return false;
            }
            return true;
        }
        
       function GoToNextPage(value){
            if(value != ""){
           document.location = 'reservation3.php?selected_no_ticket=' + value;
      }
    }
    Code:
    <form action="reservation3.php" method="post" name="movieList" 
    onSubmit="return validate(this);">
    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...

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    At the very least, you need to get rid of this:

    Code:
    onChange="GoToNextPage(this.value)"
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •