Thread: Onclick

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Onclick


    In my html page i inserted a submit button and when the button is clicked 3 javascript functions named xyZ(),abC(),deF() need to be executed.

    When all the 3 functions are executed successfully then only i want to show the hello.html page.

    But now i am getting the hello.html page even if the functions don't get executed successfully.

    <script>
    function open_win()
    {
    if(xyZ() && abC() && deF())
    window.open("hello.html","_blank","width=400");
    else
    alert("Register Again");
    }
    </script>

    <html>
    <input type="submit" onclick="xyZ(),abC(),deF(),open_win()">
    </html>


    what should i write to correct the problem?
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    I might would do something along these lines:
    Code:
    <script>
    
    var pass;
    var submit = 0;
    
    function xyZ()
    {
    alert("XYZ Function Triggered");
    submit++;
    pass = submit + "A";
    }
    
    function abC()
    {
    alert("ABC Function Triggered");
    submit++;
    pass = submit + "AB";
    }
    
    function deF()
    {
    alert("DEF Function Triggered");
    submit++;
    pass = submit + "ABC";
    }
    
    function open_win() 
    {
    // trigger all three functions
    xyZ();
    abC();
    deF();
    // validate "pass" variable
     if(pass == "3ABC") {
      window.open("hello.html","neWin","width=400,height="+Number(window.screen.height - 102)+"");
      submit = 0;
      pass="";
     }
     else {
      alert("Register Again");
     }
    }
    
    </script>
    
    <input type="button" value="Submit" onclick="open_win()"/>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    Actually i have designed a registration form in which first name,last name,user name,password etc are there.I have written validation codes for each of these individually in separate functions.One function for one validation.Like,fname() for first name and so on.

    I have also designed an html page which i want to show on successful validations of all the fields.But for that all the functions are needed to be executed first,if all the validations are satisfied,then only the html page saying "registration successful" will be displayed.
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,183
    Rep Power
    184
    You do not need 3 separate functions to validate 3 separate form fields; you only need 1 function, to validate all 3 form fields and if they are validated, then you would submit form and be redirected to or have pop-up open of "registration successful" html page. I think you need to do a little online research on JavaScript Form Validation.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by web_loone08
    You do not need 3 separate functions to validate 3 separate form fields; you only need 1 function, to validate all 3 form fields and if they are validated, then you would submit form and be redirected to or have pop-up open of "registration successful" html page. I think you need to do a little online research on JavaScript Form Validation.

    It somehow worked for me...Thanks a lot for your suggestion...""...putting all other functions inside open_win() and returning true or false values for appropriate conditions...Especially These 2 ideas worked for me...""

IMN logo majestic logo threadwatch logo seochat tools logo