EasyUI Forum
June 27, 2024, 05:29:19 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Submit Form with Link Button  (Read 23745 times)
Punkerr
Newbie
*
Posts: 37


View Profile
« on: February 21, 2013, 03:40:32 PM »

Hi guys. I have a little problem here:

HTML:
Code:
<div class="easyui-panel" style="width:167px">  
<form id="ff" method="post">
<table>  
<tr>  
<td>User:</td>
</tr>
<tr>
<td><input id="user" class="easyui-validatebox" type="text" name="user" required="true"></input></td>
</tr>
<tr>  
<td>Password:</td>
</tr>
<tr>
<td><input id="password" class="easyui-validatebox" type="password" name="password" required="true"></input></td>
</tr>
</table>
<div style="background:#fafafa;text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">Submit</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">Clear</a>
</div>
</form>
</div>

SCRIPT:
Code:
$(function(){
$('#ff').form({
url:'log_validate.php',
onSubmit:function(){
return $(this).form('validate');
},
success:function(data){
document.location.reload(true);
$.messager.alert('Access', data, 'info');
}
});
});
function submitForm(){  
$('#ff').form('submit');  
}  
function clearForm(){  
$('#ff').form('clear');  
}

The form works perfectly with: <input type="submit" value="Submit">, but when I replaced with <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">Submit</a>... doesn't work.

I searched all the forum topics and I found this solution: onClick="$('#ff').submit();", but it doesn't work either.

Any idea anybody??
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 21, 2013, 06:34:50 PM »

Calling $('#ff').submit() statement can submit the form normally. Another way to submit a form is to call 'submit' method of form plugin. The code below shows how to call 'submit' method.
Code:
$('#ff').form('submit', {
url:'log_validate.php',
onSubmit:function(){
return $(this).form('validate');
},
success:function(data){
$.messager.alert('Access', data, 'info');
}
});
Logged
Punkerr
Newbie
*
Posts: 37


View Profile
« Reply #2 on: February 23, 2013, 12:39:05 PM »

Thanks sworthy, this line was the solution: "Calling $('#ff').submit() statement can submit the form normally". I had not understood before, but now it's all clear.

Here's my code:

JSCRIPT
Code:
 			$(function(){
$('#ff').form({
url:'log_validate.php',
onSubmit:function(){
return $(this).form('validate');
},
success:function(data){
document.location.reload(true);
}
});
});

HTML
Code:
							<form id="ff" method="post">
<table>  
<tr>  
<td>User:</td>
</tr>
<tr>
<td align="center"><input id="user" class="easyui-validatebox" type="text" name="user"></input></td>
</tr>
<tr>  
<td>Password:</td>
</tr>
<tr>
<td align="center"><input id="password" class="easyui-validatebox" type="password" name="password" required="true"></input></td>
</tr>
<tr>
<td align="center"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ff').submit()">Submit</a></td>
</tr>
</table>
</form>

Now I have an "easyui-linkbutton" working Smiley
« Last Edit: February 23, 2013, 12:42:30 PM by Punkerr » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!