PDA

View Full Version : trying to adapt an AJAX example from using a submit button to an onblur



itp
11-28-2006, 04:07 AM
I am trying to adapt an AJAX example from using a submit button to an onblur. My form looks like this



<form name="form2" action="/mycgilibp/AJAX43.pgm"
method="post" target="_blank" onSubmit="submitForm(this);return false;">


My onblur looks like this. It works, but throws up a new page instead of populating the specified textarea .



value1 <INPUT TYPE="text"
value="Tabbing out of this text box should trigger a submit and display values below -NOT open a new page! "
NAME="value1" size="100"
maxlength="100"
onBlur= "document.form2.submit()">




<script type="text/javascript">
function submitForm(theform) {
var status = AjaxRequest.submit(theform,
//alert("hello");
{
'onSuccess':function(req){ document.forms['form2'].submitResults.value = req.responseText; }
}
);
return status;
}</script>



See live example here. It should make question more clear.
http://tinyurl.com/u3am7

itp
12-01-2006, 03:21 AM
I have been making some progress. I am trying to trigger an AJAX submitForm off a <select> onchange event, however the value of select is not getting passed into the backend script. Anyone have an example of this?

example:
http://tinyurl.com/yzxogd

code:



<script type="text/javascript" src="/CgidevExt/Ajax/AjaxRequest_Matt.js"></script>
<SCRIPT language="JavaScript">
function submitForm(theform)
{var status = AjaxRequest.submit(theform,
{
'onSuccess':function(req)
{ div1.innerHTML = req.responseText; document.forms['form1'].submitResults.value = req.responseText; }
} );
return status;
}
</script>


<form name="form1" action="/mycgilibp/AJAX44A.pgm"
method="post" target="_blank" onSubmit="submitForm(this);return false;">

<SELECT NAME="SelectContinent"
onChange="submitForm(document.form1);return false;">
<option value="Select a Continent" >Select a Continent </option>
<option value="Africa" >Africa </option>
<option value="America" >America </option>
<option value="Asia" >Asia </option>
<option value="Australia" >Australia </option>
<option value="Europe" >Europe </option>
</SELECT>


<textarea name="submitResults" style="width:100%;height:200px;border:solid 1px black;" disabled></textarea>
</form>
[/code]

itp
12-18-2006, 12:14 AM
Finally got them working!

Anyone with Safari or Opera can you let me know if these work for you?

Anyone with better solution let me know.

http://tinyurl.com/y89aua
http://tinyurl.com/y3seh5

itp
12-23-2006, 01:45 PM
[hmm, sometimes I think I am talking to myself.]

Can anyone tell me why only the first part of multi-name countries (eg: Costa Rica or United States) get picked up by my script on the second select box.

See second link above.

mwinter
12-24-2006, 12:34 AM
Your idea is a non-starter. Form submission should only ever occur as a direct result of activating a submit button. Forms, and the HTTP requests they generate, are one of the few reliable things on the Web and introducing a dependency on client-side code - especially "AJAX" - is a giant leap backwards, in my opinion.

Do you have permission from Matt to redistribute his code? He is an acquaintance of mine, so tread very carefully, here. :mad:

Mike