We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

is this possible

poweranger77
poweranger77 asked
on
Medium Priority
195 Views
Last Modified: 2011-09-20
i have a form, within that form, i have 3 button. I wish to submit the form to different action when user click on it... is it possible to let the javscript handle this?


<javascript>

function setActionA() {

document.test.action="ServletA";

}

function setActionB() {

document.test.action="ServletB";

}

</javascript>


<form name="testing" method="POST" >
..
..
<input type="button" value="gotoSevlet A " onClick="setActionA();" >
<input type="button" value="gotoSevlet B " onClick="setActionB();" >


What say you? If it's ridiculour, how should i make it happend?
Comment
Watch Question

rrzstudent
CERTIFIED EXPERT

Commented:
Here is one way.  But the back button doesn't  work.
<script>
function setActionA() {
                       location.replace("Setel.jsp");
}
function setActionB() {
                       location.replace("prain2.jsp");
}
</script>
<form name="testing" method="POST" >
<input type="button" value="gotoSevlet A " onClick="setActionA();" >
<input type="button" value="gotoSevlet B " onClick="setActionB();" >
</form>
rrzstudent
CERTIFIED EXPERT

Commented:
<script>
function setActionA() {
                       location.replace("url of ServletA");
}
function setActionB() {
                       location.replace("url of ServletB");
}
</script>
<form name="testing" method="POST" >
<input type="button" value="gotoSevlet A " onClick="setActionA();" >
<input type="button" value="gotoSevlet B " onClick="setActionB();" >
</form>
Commented:
Why are you struggling so much? Just do

<form name="testing" method="POST" >
<input type="button" value="gotoSevlet A " onClick="document.testing.action='ServletA';submit();" >
<input type="button" value="gotoSevlet B " onClick="document.testing.action='ServletB';submit();" >
</form>

________
radarsh

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
This is much like what you had posted but with the addition of a submit(); function
call.

________
radarsh

Author

Commented:
thank you
Simple, you can try this...

function setActionA() {

document.test.action="ServletA";
document.testing.submit();  //extra line
}

function setActionB() {

document.test.action="ServletB";
document.testing.submit();  //extra line
}

</javascript>


<form name="testing" method="POST" >
..
..
<input type="button" value="gotoSevlet A " onClick="setActionA();" >
<input type="button" value="gotoSevlet B " onClick="setActionB();" >
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.