Results 1 to 5 of 5

Thread: trying to adapt an AJAX example from using a submit button to an onblur

  1. #1
    Join Date
    Apr 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default trying to adapt an AJAX example from using a submit button to an onblur

    I am trying to adapt an AJAX example from using a submit button to an onblur. My form looks like this

    PHP Code:
      <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 .

    PHP Code:
        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()"
    PHP Code:
    <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

  2. #2
    Join Date
    Apr 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:

    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]

  3. #3
    Join Date
    Apr 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Apr 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    [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.

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •