how to redirect struts action from java script?
If the condition in the script succeeds, then I need to call one action in config xml, otherwise no actions invoking the control should remain on the same page? please help with this?
Java script
function displayDate() { var x=document.getElementsByName("userName") if(x = "shan") { alert("shankarasd"); document.myForm.action ="/setUpForInsertOrUpdate"; document.myForm.submit(); } }
HTML
<html> <body> <s:form action="HelloWorld" > <s:textfield name="userName" label="User Name" /> <s:submit onclick="displayDate()" /> </s:form> </body> </html>
config.xml
<struts> <package name="default" extends="struts-default"> <action name="HelloWorld" class="vaannila.HelloWorld.HelloWorld"> <result name="SUCCESS">/success.jsp</result> </action> <action name="setUpForInsertOrUpdate" method="setUpForInsertOrUpdate" class="vaannila.HelloWorld.HelloWorld"> <result name="SUCCESS1">/success1.jsp</result> </action> <action name="back" method="back" class="vaannila.HelloWorld.HelloWorld"> <result name="SUCCESS2">/success.jsp</result> </action> </package> </struts>
source share