Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to set action page with two different button

Posted on 2005-03-27
8
Medium Priority
?
328 Views
Last Modified: 2008-03-17
I have a form to update and delete a data record:

This is the form header:
<form method="POST" ENCTYPE="multipart/form-data" onsubmit="return Form_Validator(this, this.FILE1.value)" >

where Form_Validator is a function that validates user inputs.

These are the buttons I have:
<input type="submit" value=" Update " name="Submit"  onclick="">&nbsp;
<input type="submit" value="  Delete  " name="Submit1" onclick="">

I need to do the following:

If a user click update button, the javascript should validate the input first and then submit the form to: update_action.asp page.

If a user ckicks on delete button, the javascript should shubmit the form to delete_action.asp page.

Please help me on this.

Thank you.
0
Comment
Question by:csg_ccsd
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:RozanaZ
ID: 13638877
<HTML>
<HEAD>
<TITLE></TITLE>

<script>
      function submitForm(actionName)
      {
            formObj = document.getElementById('form1');
            textObj = document.getElementById('FILE1');
            if(Form_Validator(formObj, textObj))
            {
                  formObj.action = actionName;
                  formObj.submit();
            }
      }

      function Form_Validator(x, y)
      {
            //your validation script
            return true;
      }
</script>
</HEAD>
<BODY>
<table>
      <tr>
            <td>
                  <form method="POST" ENCTYPE="multipart/form-data" id="form1" onsubmit="" >
                        <input type="text" id="FILE1">
                        <input type="submit" value=" Update " name="Submit"  onclick="javascript: submitForm('update_action.asp')">&nbsp;
                        <input type="submit" value="  Delete  " name="Submit1" onclick="javascript: submitForm('delete_action.asp')">
                  </form>
            </td>
      </tr>
</table>
</BODY>
</HTML>
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 13638963
Two submit buttons, onclick on the submit button and unnecessary scripting are all bad practice.  My preference would be to do it this way:

<form method="POST" ENCTYPE="multipart/form-data" action="update_action.asp"
onsubmit="return Form_Validator(this, this.FILE1.value)" >
Rest of the form here.

<input type="submit" value=" Update " name="Submit">&nbsp;
<input type="button" value="  Delete  " name="Submit1"
onclick="this.form.action='delete_action.asp';this.form.submit();">

Cd&
0
 
LVL 8

Expert Comment

by:RozanaZ
ID: 13638982
Ok, I agree with you, I just tried to do this as close to question condition as I could...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13639405
Unless the submit is made through a submit button the onsubmit command is not executed, eg

<form action="http://google.com/search" onsubmit="alert('going to google' );return true">
 <input name="q"><p>
 <input type="submit" value="submit1"><p>
 <input type="button" value="submit2" onclick="this.form.submit()"><p>
</form>

and

<form action="http://google.com/search" onsubmit="alert('going to google' );return true">
 <input name="q"><p>
 <input type="submit" value="submit1"><p>
 <input type="submit" value="submit2"><p>
</form>


I suggest this

<form method="POST" ENCTYPE="multipart/form-data" onsubmit="return Form_Validator(this, this.FILE1.value)" >
  <p><input type="submit" value="delete" onclick="this.form.action='delete_action.asp';return true"></p>
  <p><input type="submit" value="update" onclick="this.form.action='update_action.asp';return true"></p>
</form>

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13639448
There is not requirement to validate for the delete; only the update. So you do the normal sumit for update and the onsubmit fires; then for the delete all you need is the onclick to change the action and submit.  You don't need two submit buttons.

Look at the question, there is no requirement to validate the delete.

Cd&
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 13639464
you are correct. This is a very clunky design.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 13639530
even better would be to have the asp look at request.form("Submit1")==" Delete "

No scripting and it would work if scripting was disabled
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13642970
Glad we could help.  Thanks for the A. :^)

Cd&
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question