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 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2004
    Location
    Saint Peters, Missouri, USA
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Using onClick event to go to another page

    I hope someone can help with the difficulty I'm having moving from one page to the next.

    My problem is with the onClick event. If I preface the event with a call to the function (as per the code snippet below); and the function returns a true, then the window.location doesn't execute (the same as if the function returns a false).

    If I preface the onClick event with the window.location, i.e.
    onClick="window.location='devSimpleForm.asp?cmdAction=ptoTest&employee=' + document.form1.employee.value"; return empSelected(this) >

    the function call is still executed, but, even with a False, the new page (devSimpleForm.asp) still loads & runs.

    I already have a 'submit' button used to open a different page, so I seem to be stuck with the onClick event handler.

    Can anyone help so that a 'false' won't load/run the next page, and a 'true' will?

    function empSelected(objForm) {

    if (form1.employee.value == "") {
    alert("You must choose an employee!")
    form1.employee.focus()
    return false
    }
    alert("We're being returned with TRUE")
    return true
    }//-----------------------------

    <input type="button" name="test" value="Simple Form"
    onMouseover="window.status='Click for test'; return true"
    onMouseOut="window.status=' '; return true"
    onClick="return empSelected(this); window.location='devSimpleForm.asp?cmdAction=ptoTest&employee=' + document.form1.employee.value" >

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alter your onClick handler to include an if statement:
    Code:
    onClick="if(empSelected(this)) { window.location='devSimpleForm.asp?cmdAction=ptoTest&employee=' + document.form1.employee.value; }"
    Sadiq.

  • #3
    New Coder
    Join Date
    Aug 2004
    Location
    Saint Peters, Missouri, USA
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Omigosh!!! It works GREAT!



    Beaucoup Thanx! SAD69


  •  

    Posting Permissions

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