EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: peter900 on April 24, 2016, 03:12:17 PM



Title: Updating Form fields after submission
Post by: peter900 on April 24, 2016, 03:12:17 PM
I am exploring how EUI forms could be used for volume data input.  I want to be able make changes to the fields after a submission in readiness for the next entry.  For example, to retain some fields, to blank others and to allow some manipulation such as running an incrementing counter.

I thought it might be possible to do something in the success: routine.  But this doesn't work.

Code:
$(function(){
$('#ff').form({
url:'form3_proc.php',
onSubmit:function(){
return $(this).form('validate');
},
success:function(data){
$.messager.alert('Info', data, 'info');
alert ("ddd");
var txt = $('#name');
                    txt.val("updated " + txt.val());
}
});
});

Any help to point me at some sample code to do something along these lines would be much appreciated. Thanks.


Title: Re: Updating Form fields after submission
Post by: peter900 on April 28, 2016, 04:38:38 AM
The solution to updating a form field after submission, for example setting the name field to "",  is:

$('input[name="name"]').val("");

[ To retrieve a field value use  var email = $(“myfield“).val(); where myfield is an id.  ]

Here is a trivial example of using a php function ( in this case just returning server time ) to place a value directly into a form field - not actually an EasyUI form in this case  but the principal is the same for all jQuery forms.


Code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.post("post_receiver2.php", {  },
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
    $('input[name="fname"]').val(data);
        });
    });
});
</script>
</head>
<body>

<form id='userForm'>
    <div><input type='text' name='fname' placeholder='Firstname' /></div>
   
</form>

<button>Submit !</button>

</body>
</html>

Here is the code in post_receiver2.php

Code:
	
echo date("h:i:sa");

This means that, in a volume input situation,  it is possible to retain selected field values and update read only fields with values drawing on php power.