call a php function to autofill a form field
I have a php function string_creator($length) to create a random string. When I want to autofill a form field with that php function via a link, I was using sajax script. It was something like:
- <?php
sajax_init();
sajax_export("string_creator");
sajax_handle_client_request();
?>
<script type="text/javascript">
function string_creator_complete(key) {
if (key == "") {
alert("error");
} else {
document.forms.formName.fieldName.value = key;
}
}
</script>
<input type="text" name="fieldName" value="" />
<a href="javascript:x_string_creator(8, string_creator_complete);">Create a string</a>
When I click "Create a string" link, the "fieldName" field was autofill with the value returned from that php function.
Now I want to move to jQuery from sajax. Is it possible? How?