Eshko,
Do you really mean AJAX?
Form submission is a feature of bog-standard HTML/HTTP and can be triggered either by the user clicking the form's submit button or from javascript, eg, forms[0].submit() , which is safe as long as you have just one form on the page. This approach will send a standard HTTP request and will cause the page to be refreshed or renewed depending on the form's action .
Yes, you can cause form data to be submitted via an "AJAX request" but you only do this when you need to submit the data without refreshing/renewing the page. I don't have time to get into a lengthy description of the javascript involved, but it is well very documented on the web.
In itself, "auto submit" infers the first type of request, which is why I question "AJAX". It is not uncommon for folks to think they are using AJAX when they are not (with sincere appologies if this doesn't apply to you).
Maybe you could advise as to which type of HTTP request you are using and also post some code (HTML & JS) so we can see what might be wrong.Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Eshko,
OK, that sounds like genuine AJAX.
Would I be correct in understanding that you need to trigger an existing ajax script in response to a user event other than button click? If so it's trivial but I must fly now. I'm running late. Maybe Essential will come back ( he's very reliable :) ). If not I'll be here again in a few hours.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
And with any luck my Daniweb email alerts will be arriving today .....
:(
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Whoops, I just discovered Page 2 after drafting something.
Much simpler than Essential's but here it is anyway:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="javascript" type="text/javascript">
function checkForm(f){
var barcodeDefault = "Enter a barcode";
if( f.barcode.value == '' || f.barcode.value == barcodeDefault ){
f.barcode.value = barcodeDefault;
return false;
}
else{ return true; }
}
onload = function(){
checkForm(document.forms.barcodeForm);
}
</script>
</head>
<body>
<form id="barcodeForm" action="action.php" method="post" onsubmit="return checkForm(this);">
<input name="barcode" type="text" value="" onfocus="this.value=''" onblur="if(checkForm(this.form))this.form.submit();" />
<input type="submit" value="Add" />
</form>
</body>
</html>
As you will see, two events, barcode onblur and clicking Add, both cause the function checkForm() to be called, which in turn calls barcodeValid() (my test is VERY simple and can no doubt be improved).
On failure, checkForm puts a message in the barcode field and returnns false - thereby suppressing form submission. If the barcode is valid then the function returns true and form submission is allowed.
Just to round things off, checkForm is called on page load to cause the "Enter a barcode" message to appear in the barcode field by default.
I think that's about it. Probably too simple but the general structure may be about right.
Hope it helpsAirshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
Appologies, my script doesn't quite tally with my decription. I did a last minute change and forgot to re-paste it from the editor (FirstPage 2000 recommended). However the change was of no great import and the version I posted is functionally identical.
Airshow
Airshow
WiFi Lounge Lizard
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372