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
    Mar 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting which button was pressed after and onchange event

    I have a form created in an ASP. On the form are several buttons, one of which is SAVE. Also on this form is a text box that has an ONCHANGE event. This ONCHANGE event executes a function that manipulates the URL. When the value in the textbox is changed and the SAVE button is pressed without tabbing out of the textbox, the ONCHANGE event is triggered. Then processing returns to the form as though the SAVE button is just acting like a tab. The SAVE button is defined as so: <input type=Button name=dataaction value=save>. I tried to detect the button by using the javascript document.forms[0].dataaction.value but there is nothing there.

    I need to be able to know that the button pressed was the SAVE button and not one of the other ones on the form. Can anyone suggest how to detect the button pressed??

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ...use an 'onclick' event handler perhaps?

    Code:
    <input type="button" name="dataaction" value="Save" 
    onclick="jav&#97;script:alert('You clicked the Save button')" />
    Just replace the jav&#97;script:alert with your function call like onclick="myFunction()"

    Hope that helped. Cheers

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is pretty much what I am doing.
    <input type="button" name="dataaction" value="Save" onclick="myfunction()">
    Essentially myfunction() is:


    var ButtonClicked = document.forms[0].dataaction.value;
    alert ("Button clicked is: " + ButtonClicked);



    The result is : ButtonClicked is undefined.

  • #4
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try this... Revisited
    Code:
    <script language="javascript" type="text/javascript">
    <!--
    function  buttonTest(btn){
    alert("Button clicked is: " + btn.value)
    }
    //-->
    </script>
    ...with this form in the body:
    Code:
    <form>
    <input type="button" name="dataaction" value="Save"
    onclick="buttonTest(this)">
    <input type="button" name="dataaction" value="Help"
    onclick="buttonTest(this)">
    <input type="button" name="dataaction" value="Close"
    onclick="buttonTest(this)">
    </form>
    Last edited by HairyTeeth; 03-28-2003 at 10:11 PM.


  •  

    Posting Permissions

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