Foros de discusión

Ajax submission & button submission in same form

Jenny Han, modificado hace 14 años.

Ajax submission & button submission in same form

Junior Member Mensajes: 36 Fecha de incorporación: 17/01/08 Mensajes recientes
I have a form contains 2 text boxes and one button. The requiement is if any text box have changes,and if user click outside of the form, the value of text box should submit to action class without fresh screen. If user click button, the button shouls submit as regular form submission. I use ajaxutil for first submission on onfocuseout() handler.

My problem is that after enter value in text1 and text2,then click ajaxcall() is called, but button action is never called? if just click button,button action works. How can I shut the ajax call when i click button? if I add if(m=="button") return in ajaxcall, click even still not fire off.

<script>
function ajaxcall(){
var m=document.activeElement.id;
if ((m=="text1")||(m=="text2")){
return;
}
var form =document.getElementById("fm");
var inputs = jQuery("input, textarea, select", form);

form.action="<portlet:actionURL windowState='<%= LiferayWindowState.EXCLUSIVE.toString() %>'>
<portlet:param name='struts_action' value='/mywork/action' /></portlet:actionURL>";

var url = form.action + "&" + inputs.serialize();
AjaxUtil.update(url, "<portlet:namespace />lib");
//set window state back to normal
}
</script>

<div id="<portlet:namespace/>lib1" onfocusout="ajaxcall();"/>
<html:form action="/mywork/action?actionURL=true" method="post" styleId="fm">
<table>
<tr><td>

<b>text1:</b><html:text name="myworkform"
property="text1" styleId="text1"
/>
</td><td>
<b>text2:</b><html:text name="myworkform"
property="text2" styleId="text2" />
</td></tr>
</table>
<html:submit styleClass="graybutton" property="mybutton" value="mybutton" styleId="button" />
</html:form>
</div>