Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.location() problem

    Hi! can anyone help me here,whats wrong with the codes below.I want to direct user to another page tryn2.html or tryn3.html depending on the selection user made in the select field.The window.location() function doesn't work the way it should be
    Code:
    html>
    <head><title>clr</title>
    <script type="text/javascript">
    function validate_form ( ){
     if ( document.myform.nam.selectedIndex == 1 )
            {
                var valid=confirm ( "Are u sure?" );
                if(valid==true){
                    
                    window.location=("tryn2.html");  
                   
                }else{
                    window.location=('tryn3.html');  
                }
            }
    }
    </script>
    </head>
    <body>
    
    <form name="myform" onSubmit="return validate_form ( );">
    <select name="nam">
    <option>Select one..</option>
    <option>Delete</option>
    <option>George</option>
    </select>
    <input type="submit" value="submit">
    </form>
    </body>
    <html>

  • #2
    JUD
    JUD is offline
    New Coder
    Join Date
    Jul 2005
    Location
    I'm right here
    Posts
    92
    Thanks
    0
    Thanked 2 Times in 2 Posts
    There's no need for the parentheses after window.location.

    Use
    Code:
    window.location = 'tryn2.html'
    instead of
    Code:
    window.location = ('tryn2.html')
    Last edited by JUD; 08-27-2008 at 02:11 PM.

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this


    Code:
    <html>
    <head><title>clr</title>
    <script type="text/javascript">
    function validate_form(){
     if ( document.myform.nam.selectedIndex == 1 )
            {
                var valid=confirm ( "Are u sure?" );
                if(valid==true){
                    
                    window.location = "tryn2.html" ;  
                   
                }else{
                    window.location = "tryn3.html" ;  
                }
            }
    }
    </script>
    </head>
    <body>
    
    <form name="myform" onSubmit="validate_form(); return false;">
    <select name="nam">
    <option>Select one..</option>
    <option>Delete</option>
    <option>George</option>
    </select>
    <input type="submit" value="submit">
    </form>
    </body>
    <html>
    Last edited by mugalata; 08-27-2008 at 02:20 PM.

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    26
    Thanks
    0
    Thanked 1 Time in 1 Post
    and in your if statement

    if(valid){

    }
    else{

    }


  •  

    Posting Permissions

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