?
Solved

How to set action page with two different button

Posted on 2005-03-27
8
Medium Priority
?
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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

764 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