2 button form + which button was pressed
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

2 button form + which button was pressed

From: <Bill_W_Stephens@yahoo.com>
Date: Tue Apr 04 2006 - 05:23:45 CEST

I need a form with two buttons and ability to detect which button was
pressed. I got this code to work using a javascript global variable,
but I know there must be a better way using DOM. Any suggestions?

<html>
<head>
<script language="JavaScript" type="text/javascript">
// global var: which button I am pressing
var btnWhichButton;
//========================================================
// Check the input fields of the form
//========================================================
 function chkMyForm() {
    alert(btnWhichButton.value);
    document.SubmitExpenseForm1.action="#";

        // If Delete Record
         if (btnWhichButton.value == "Delete Record")
        {
                document.SubmitExpenseForm1.DeleteRecordParm.value = 'Y' ;
                window.document.SubmitExpenseForm1.submit();
                   return;
        }

        // Otherwise do validation
           chkTextArea();
        document.SubmitExpenseForm1.DeleteRecordParm.value = 'N' ;
           window.document.SubmitExpenseForm1.submit();
}

//========================================================
// Check Text Area
//========================================================

function chkTextArea() {
// additional validation...
alert("Extra Validation done here")
}

</script>

</head>
<body>

        <form class="noLF" name="SubmitExpenseForm1"
action="javascript:chkMyForm();" >
        <input TYPE=HIDDEN NAME="ExpenseCode" value="AUTO">
        <input TYPE=HIDDEN NAME="AcctPeriod" value="02">
        <input TYPE=HIDDEN NAME="AcctYear" value = "2006">
        <input type="hidden" name="DeleteRecordParm">

        <!-- Submit Record Button -->
        <input type="submit" NAME="Submit" value="Submit Record"
onclick="btnWhichButton=this">

        <!-- Delete Record Button -->
        <input type="submit" NAME="DeleteRecord" value="Delete Record"
onclick="btnWhichButton=this">
        
        </form>

        </BODY>
        </HTML>
Received on Mon May 1 04:39:43 2006