SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: ajax problem

  1. #1
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax problem

    function check_obj_call(frm)
    {
    var xmlHTTPObj ;

    serverURL="http://localhost/mydir/ajax_file.php";

    xmlHTTPObj=getXML_HTTPObj();
    xmlHTTPObj.open("GET",serverURL+"?zipCode="+frm.zip.value,true);

    xmlHTTPObj.onreadystatechange = function()
    {
    if(xmlHTTPObj.readyState == 4 && statuse)
    {
    var serverText = xmlHTTPObj.responseText;

    if(serverText == 'zip code not found')
    {
    alert("ZIP code is not valid, Please enter proper ZIP codesd");
    document.getElementById('change_field').value = 0;
    return false;
    }
    else
    {
    document.getElementById('change_field').value = 1;
    return false;
    }
    }
    }
    xmlHTTPObj.send(null);
    return false;
    }

    above function is call to check whtehr i have that zipcode in database or not.

    sequence is:

    name
    address
    zip
    interest
    education

    so validation of zip is at position third and after zip i have to validate interest and education also.....

    but this function return true and simply submits the form !!!!
    it return false

    validation:
    ----------

    if(frm.zip.value.length != '')
    {
    var return_val=check_obj_call(frm);
    if(return_val == false)
    {
    alert("ZIP code is not valid, Please enter proper ZIP codesd");
    frm.zip.focus();
    return false;
    }
    }

    i have no idea what sud i do now

    !!!!

    If i write alert in above sniipet things will go fine but if no alert is kept then it will simply submit the form ignoring the rest of the vcalidation

    kindly help me in this.

    Thanks

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    i have no idea what sud i do now
    It's a Js question, so post it in the Js forum - not the PHP forum.

    p.s. this looks wrong, length returns in integer, surely?
    if(frm.zip.value.length != '')

    if(frm.zip.value.length > 0 ) , no?


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
  •