2 submit buttons in 1 form

Results 1 to 3 of 3

Thread: 2 submit buttons in 1 form

  1. #1
    celeste Guest

    Default 2 submit buttons in 1 form

    what if i have a form with a modify and delete button .... how can i pass the information if i choose modify the info will go to page2 and if i choose delete the info will go to page3?

  2. #2
    Sreedharan Guest

    Default Two ways: 2 submit buttons in 1 form

    You can do this in two ways:<BR><BR>In the onClick event of each button, call a function, Eg<BR><BR>&#060;input name="cmdSave" type="button" value="Save" onClick="fSaveData();"&#062;<BR>&#060;input name="cmdDelete" type="button" value="Delete" onClick="fDeleteData();"&#062;<BR><BR>&#060;script language=Javascript&#062;<BR>&#060;!--<BR>function fSaveData()<BR>{ var strID = document.forms[0].txtID.value;<BR> var strName = document.forms[0].txtName.value;<BR> var URL = "Page1.asp?ID=" + strID + "&NAME=" + strName;<BR> location.href = URL;<BR>}<BR><BR>// Do the same thing for the Delete button<BR><BR>function fDeleteData()<BR>{ var strID = document.forms[0].txtID.value;<BR> // You may only want ID for deleting<BR> var URL = "Page21.asp?ID=" + strID; <BR> location.href = URL;<BR>}<BR><BR><BR>Second Method:<BR>Instead of type=button above, use type="submit".<BR><BR>In your ASP page, check which button has been clicked<BR>&#060;% If Trim(Request.Form("cmdSave")) &#060;&#062; "" Then<BR> &#039; Do your saving stuff here, then redirect<BR> Response.Redirect "Page1.asp"<BR> End If<BR> If Trim(Request.Form("cmdDelete")) &#060;&#062; "" Then<BR> &#039; Do your Deleting operation here, then redirect<BR> Response.Redirect "Page2.asp"<BR> End If<BR> %&#062;<BR>

  3. #3
    Join Date
    Dec 1969

    Default also..

    you can use the action property to alter where the form goes..<BR>&#060;input type=button name="button1" value="save" onclick="document.formName.submit()"&#062;<BR>&#06 0;input type=button name="button2" value="delete" onclick="setForm()"&#062;<BR><BR>&#060;script language="javascript"&#062;<BR>function setForm(){<BR>var someOtherURL = "http://nowhere.com/theDeleter.asp";<BR>document.formName.action = someOtherURL;<BR>document.formName.submit();}<BR>& #060;/script&#062;<BR><BR>.. i&#039;m not sure if this is the exact way to do this, but basically its all here. this may or may not be supported in all versions of netscape, but works with ie.

Posting Permissions

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