[thelist] JS: test which submit button was clicked.

apathetic timbooker at gmail.com
Fri Jun 4 11:01:46 CDT 2004


Because you've created multiple buttons with the same name, what you
now have is an array of input buttons.  I would suggest adding a
custom property to the button onclick, and then looping through the
array of buttons and testing which has been set.

Sample code:

<script type="text/javascript">

    function TestRejection( f ) {
   
        var flds = f.WhatToDo;
        var val = '';
        
        for( var i = 0; i < flds.length; i++ ) {
            if( flds[ i ].clicked ) {
                val = flds[ i ].value;
            }
        }            
        if( val == 'Reject' ) {                
            return confirm( 'Are you sure you want to reject this
item?' );
        } else { 
            return true;
        }
    }

</script>

<form name="FormName" onSubmit="return TestRejection(this);">
    
    <input type="submit" name="WhatToDo" value="Approve"
onclick="this.clicked = true;">
    <input type="submit" name="WhatToDo" value="Reject"
onclick="this.clicked = true;">
    
</form>

Tim


More information about the thelist mailing list