Onblur does not update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • edwire
    New Member
    • Jul 2007
    • 31

    Onblur does not update

    I'm trying to update the form's text box city, state from the user input using onblur, focus. So far 3 days and zero results!
    here is my code:

    phpcode: newcityState.ph p

    [CODE=php]<?php
    /**
    * Connects to the database.
    * Return false if connection failed.
    * Be sure to change the $database_name. $database_usern ame , and
    * $database_passw ord values to reflect your database settings.
    */
    function db_connect() {
    $database_name = 'records'; // Set this to your Database Name
    $database_usern ame = 'code'; // Set this to your MySQL username
    $database_passw ord = 'exe:exe'; // Set this to your MySQL password
    $result = mysql_pconnect( 'localhost',$da tabase_username , $database_passw ord);
    if (!$result) return false;
    if (!mysql_select_ db($database_na me)) return false;
    return $result;
    }
    $conn = db_connect(); // Connect to database
    if ($conn) {
    $zipcode = $_GET['param']; // The parameter passed to us
    $query = "select * from zipcodes where zipcode = '$zipcode'";
    $result = mysql_query($qu ery,$conn);
    $count = mysql_num_rows( $result);
    if ($count > 0) {
    $city = mysql_result($r esult,0,'city') ;
    $state = mysql_result($r esult,0,'state' );
    $areacode = mysql_result($r esult,0,'areaco de');
    }
    }
    if (isset($city) && isset($state) && isset($areacode )) {
    $return_value = $city . "," . $state . "," . $areacode;
    }
    else {
    $return_value = "not correct".",".$_ GET['param']; // Include Zip for debugging purposes
    }
    echo $return_value; // This will become the response value for the XMLHttpRequest object
    ?>[/CODE]


    What am I doing wrong? just can't figure out! please help!

    thank you!

    Ed
    Last edited by edwire; Jul 22 '07, 05:48 PM. Reason: wrong info
  • epots9
    Recognized Expert Top Contributor
    • May 2007
    • 1352

    #2
    where is your html that uses onblur and where is the javascript that onblur uses?

    Comment

    • edwire
      New Member
      • Jul 2007
      • 31

      #3
      I can not post the html code! I/m getting an error: the message is too short? I know the message is long! wht's wrong with the submissing form?

      Ed

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        Originally posted by edwire
        I can not post the html code! I/m getting an error: the message is too short? I know the message is long! wht's wrong with the submissing form?

        Ed
        it doesn't count the characters in the code tags, so after u insert your html/javascript into code tags, explain what it is trying to do. then it should post with no problems.

        Comment

        • edwire
          New Member
          • Jul 2007
          • 31

          #5
          Originally posted by epots9
          it doesn't count the characters in the code tags, so after u insert your html/javascript into code tags, explain what it is trying to do. then it should post with no problems.

          I've tried everything and does not work the submit option, it keeps telling me there's not enough characters?

          I've loaded the HTMLcode to this page: http://www.echildcarem anagement.com/prototype/step6.html

          Thanks for your time!

          Ed

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Ed.

            There is a problem with our site's post rendering engine. It has a hard time with large amounts of code inside of CODE tags. For now, here's your code, sans CODE tags.

            <script language="JavaS cript" SRC="include/jsfunction.js"> </script>
            <SCRIPT language=JavaSc ript>
            var strflag=1;
            function validation(frm)
            {
            if (mf_validation( frm.txt_firstna me, "B", "Please Enter Your First Name...")==fals e) return false;
            if (mf_validation( frm.txt_lastnam e, "B", "Please Enter Your Last Name...")==fals e) return false;
            // if (mf_validation( frm.txt_compnam e, "B", "Please Enter Your Company Name...")==fals e) return false;

            if (mf_validation( frm.txt_compadd 1, "B", "Please Enter Address...")==f alse) return false;
            if (mf_validation( frm.txt_compcit y, "B", "Please Enter City...")==fals e) return false;
            if (mf_validation( frm.sel_state, "B", "Please Enter State...")==fal se) return false;
            var str=frm.txt_zip code.value;
            if(str!='')
            {
            if(!isNaN(str))
            {
            if (str.length!=5 )
            {
            alert("Please Enter ZIPCODE OF SIZE 5");
            frm.txt_zipcode .focus();
            return false;
            }

            }
            else
            {
            alert("Please Enter Numric ZIPCODE");
            frm.txt_zipcode .focus();
            return false;
            }
            }
            else
            {
            alert("Enter Zipcode");
            frm.txt_zipcode .focus();
            return false;
            }
            if (mf_validation( frm.txt_email, "B", "Please Enter Your Email Address...")==f alse) return false;
            if (mf_validation( frm.txt_email, "E", "Please Enter Your Email Address...")==f alse) return false;
            if (mf_validation( frm.txt_phone, "B", "Please Enter Your Phone Number...")==fa lse) return false;
            var valid = new Object();
            //var phoneNumber1 = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
            var phoneNumber1 = /^\d{3}-\d{3}-\d{4}$/;
            // var phoneNumber1 = /^\([1-9]\d{2}\)\s?\d{3} \-\d{4}$/;

            var gotIt = phoneNumber1.ex ec(frm.txt_phon e.value);

            if(! gotIt){
            var phoneNumber2 = /^\d{10}$/;
            var gotIt2 = phoneNumber2.ex ec(frm.txt_phon e.value);
            if(! gotIt2){
            alert("Please Enter Your Phone Number in Correct Format xxx-xxx-xxxx or xxxxxxxxxx");
            frm.txt_phone.s elect();
            frm.txt_phone.f ocus();
            return false;
            }
            }
            // if (mf_validation( frm.phone_ext, "N", "Ext No. Should be Numeric value...")==fal se) return false;
            var p=frm.phone_ext .value;
            if(p!="")
            {


            var phoneNumber2 = /^\d{4}/;
            var gotIt2 = phoneNumber2.ex ec(frm.phone_ex t.value);
            if(! gotIt2)
            {
            alert("Ext No. Should be min 4 Digit ");
            frm.phone_ext.s elect();
            frm.phone_ext.f ocus();
            return false;
            }


            }
            // if (mf_validation( frm.txt_faxno, "B", "Please Enter Your Fax Number...")==fa lse) return false;



            if(frm.txt_cell no.value!=""){
            // if (mf_validation( frm.txt_cellno, "N", "Mobile Number Should be Numeric value ...")==false) return false;
            var gotIt = phoneNumber1.ex ec(frm.txt_cell no.value);

            if(! gotIt)
            {
            var phoneNumber2 = /^\d{10}$/;
            var gotIt2 = phoneNumber2.ex ec(frm.txt_cell no.value);
            if(! gotIt2)
            {
            alert("Please Enter Your Mobile Number in Correct Format xxx-xxx-xxxx or xxxxxxxxxx");
            frm.txt_cellno. select();
            frm.txt_cellno. focus();
            return false;
            }
            }
            }

            //if (mf_validation( frm.txt_cellno, "B", "Please Enter Your Cell Number...")==fa lse) return false;

            frm.btnSerive1. style.color="#F F0000";
            frm.btnSerive1. value="Processi ng..";
            return true;
            }
            function updatecityState ()
            {
            var frm=document.fo rm1;
            var zip=frm.txt_zip code.value;
            frm.btnSerive1. style.color="#F F0000";
            frm.btnSerive1. value="Processi ng..";
            frm.txt_email.f ocus();
            window.frm_city .location.href= 'prototype/newcityState.ph p?param=';
            //return true;
            }
            //-->

            </SCRIPT>

            <html lang="en">
            <head>
            <title>Welcom e </title>
            <meta name="author" content="Pace Computing Limited - http://www.pc-limited.com">
            <meta name="ROBOTS" content="NOINDE X, NOFOLLOW">
            <link rel="stylesheet " type="text/css" href="styles.cs s">
            <link rel="stylesheet " href="images/css.css" type="text/css">
            </script>
            </head>

            <body>

            <div align="center">
            <table border="0" cellpadding="0" cellspacing="0" width="750">
            <tr>
            <td height="132" width="750" background="htt ps://www.wmd.com/images/pagebackgrond.j pg">
            <!--Begin Flash Header- Flash prevents HTML 4.01 Validation -->
            <!--End Flash Header-->
            </td>
            </tr>
            <tr>
            <td height="132" width="750" background="ima ges/pagebackgrond.j pg">
            <div align="center">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
            <td width="750" valign="top">
            <div align="center">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
            <td width="100%" background="ima ges/formtop.gif" height="18">&nb sp;</td>
            </tr>
            <tr>
            <td width="100%" background="ima ges/formmid.gif" valign="top">
            <div align="center">
            <table border="0" cellpadding="0" cellspacing="0" width="98%">
            <tr>
            <td valign=top align=left><lin k rel="stylesheet " href="images/css.css" type="text/css">
            <form method="post" name="form1" action="/servicerequest1 .php" enctype="multip art/form-data">
            <table width="96%" border="0" cellspacing="0" cellpadding="0" align="center">
            <tr>
            <td width="1" bgcolor="FFFFFF "></td>
            <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="1" bgcolor="ffffff "></td>
            </tr>
            <tr>
            <td>

            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="20">

            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>

            <td valign="top" align="left">

            <div id=zip1 style="display: none" class=text>
            Computer Report<br>
            <div id=zip2 class=text>

            </div>
            (866) 777-8888 <br></div>
            </td>

            <td width="75%" valign="top">

            <span class="headingB old" > Online Service Request Form</span>

            </td>
            </tr>
            </table>

            </td>
            </tr>
            <tr>
            <td height="20">
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td height="21">
            <div align="left" class="textbold 1Copy">
            <p>Schedule Your </div>
            </td>
            <td height="21">
            <div align="right">
            <p class="textbold 1Copy">Step 1-3
            </div>
            </td>
            </tr>
            </table>
            </td>
            </tr>

            <tr>
            <td bgcolor="#FFFFF F" height="45">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td >
            <div align="center"> <span class="smaller" >Use of this
            form will create a cm Service Request<br>
            and a user account for future use if needed</span>
            <br>
            <span class="red">* Indicates required field</span>
            </div>
            </td>
            </tr>
            <tr>
            <td height="8" class="bottom_b order">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td>&nbsp;</td>
            </tr>
            </table>
            </td>
            </tr>
            </table>
            </td>
            </tr>
            </table> </td>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="4" >
            <tr align="center">
            <td height="18" >
            <div id=err1 style="display: none">
            <table width='80%' border='0' cellspacing='0' cellpadding='0' >
            <tr>
            <td width='8'><img src='images/wbox_tl.gif' width='8' height='8' /></td>
            <td width='99%' bgcolor='#FF330 0'><img src='images/spacer.gif' width='20' height='8' /></td>
            <td width='8'><img src='images/wbox_tr.gif' width='8' height='8' /></td>
            </tr>
            <tr>
            <td width='8' bgcolor='#FF330 0'><img src='images/spacer.gif' width='8' height='10' /></td>
            <td width='99%' bgcolor='#FF330 0' valign=top><tab le valign=top border='0' cellpadding='0' cellspacing='0' class='infomess age'>
            <tr>

            <td valign=top><img src='images/wbox_i.gif' /></td>
            <td valign=top><img src='images/spacer.gif' width='10' height='8' /></td>
            <td><b class=textWhite >Invalid Information ...</b>
            <span class=textWhite id=err2>

            </span>
            </td>
            </tr>
            </table></td>
            <td width='8' bgcolor='#FF330 0'><img src='images/spacer.gif' width='8' height='10' /></td>
            </tr>
            <tr>

            <td width='8'><img src='images/wbox_bl.gif' width='8' height='8' /></td>
            <td width='99%' bgcolor='#FF330 0'><img src='images/spacer.gif' width='20' height='8' /></td>
            <td width='8'><img src='images/wbox_br.gif' width='8' height='8' /></td>
            </tr>
            </table> </div>
            </td>
            </tr>
            <tr>
            <td width="480" valign="top" align="left">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" >
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="1" cellpadding="2" >
            <tr>
            <td class=text valign=center
            width="38%" size=30 align="right"> <font color=red>*
            </font>First Name :&nbsp; </td>
            <td valign=center width="62%" size=30 align="left">
            <input type="text" size="30" name="txt_first name" value="" class="box1">
            </td>
            </tr>
            <tr>
            <td class=text valign=center align=left
            width="38%">
            <div align="right">< font color=red>*</font>
            Last Name :&nbsp;</div>
            </td>
            <td valign=center width="62%" align="left">
            <input type="text" size="30" name="txt_lastn ame" value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="15" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="7"></td>
            </tr>
            <tr>
            <td height="1" bgcolor="#00CCF F"></td>
            </tr>
            <tr>
            <td height="7"></td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td class=text valign=center align=right
            width="38%" size=30>
            <div align="right">C ompany Name :&nbsp;</div>
            </td>
            <td valign=center width="62%" size=30 align="left">
            <input type="text" size="30" name="txt_compn ame" value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="15">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="7"></td>
            </tr>
            <tr>
            <td height="1" bgcolor="#00CCF F"></td>
            </tr>
            <tr>
            <td height="7"></td>
            </tr>
            </table>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td class=text valign=center align=right
            width="38%" size=30>
            <div align="right">< font color=red>* </font>Address
            1 :&nbsp;</div>
            </td>
            <td valign=center width="62%" size=30 align="left">
            <input type="text" size="35" name="txt_compa dd1" value="" class="box1">
            </td>
            </tr>
            <tr>
            <td class=text valign=center align=right
            width="38%">
            <div align="right">A ddress 2 :&nbsp;</div>
            </td>
            <td valign=center width="62%" align="left">
            <input type="text" size="35" name="txt_compa dd2" value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="15" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="7"></td>
            </tr>
            <tr>
            <td height="1" bgcolor="#00CCF F"></td>
            </tr>
            <tr>
            <td height="7"></td>
            </tr>
            </table>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td class=text valign=center align=right
            width="38%">
            <div align="right">< font color=red>*</font>
            ZipCode :&nbsp;</div>
            </td>
            <td valign=center width="62%" align="left">
            <input type="text" size="30" maxlength="5" name="txt_zipco de" value="" class="box1" onBlur="return updatecityState ();">
            </td>
            </tr>
            <tr>
            <td class=text valign=center align=right
            width="38%">
            <div align="right">< font color=red>*</font>
            City :&nbsp;</div>
            </td>
            <td valign=center width="62%" align="left">
            <input type="text" size="30" name="txt_compc ity" id="txt_compcit y" value="" class="box1">
            </td>
            </tr>
            <tr>
            <td class=text valign=center align=right
            width="38%">
            <div align="right">< font color=red>*</font>
            State :&nbsp;</div>
            </td>
            <td class=text valign=center width="62%" align="left">
            <input type="text" size="30" name="sel_state " id="sel_state" value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="15" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="7"></td>
            </tr>
            <tr>
            <td height="1" bgcolor="#00CCF F"></td>
            </tr>
            <tr>
            <td height="7"></td>
            </tr>
            </table>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td width="38%">
            <div align="right">< font color=red><span class="starfiel d">*</span></font>
            <span class="text"> E-mail : </span></div>
            </td>
            <td width="62%">
            <input type="text" size="30" maxlength="75" name="txt_email " value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td width="38%">
            <div align="right">< font color=red><span class="starfiel d">*</span></font>
            <span class="text"> Phone : </span></div>
            </td>
            <td width="62%">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td>
            <input type="text" size="30" maxlength="15" name="txt_phone " value="" class="box1" >
            </td>
            </tr>
            <tr>
            <td class="red">(e. g. xxx-xxx-xxxx)</td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td width="38%">
            <div align="right">< span class="text">
            Ext. : </span></div>
            </td>
            <td width="62%">
            <input type="text" size="5" maxlength="5" name="phone_ext " value="" class="box1">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td width="38%">
            <div align="right">< span class="text">Mo bile
            : </span></div>
            </td>
            <td width="62%">
            <input type="text" size="30" maxlength="15" name="txt_celln o" value="" class="box1">
            </td>
            </tr>
            </table>

            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="15" >
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
            <tr>
            <td height="7"></td>
            </tr>
            <tr>
            <td height="1" bgcolor="#00CCF F"></td>
            </tr>
            <tr>
            <td height="7"></td>
            </tr>
            </table>
            </tr>
            <tr>
            <td>
            <table width="100%" border="0" cellspacing="2" cellpadding="2" >
            <tr>
            <td class=text valign=center align=right
            width="38%"> How do you hear about us ? </td>
            <td valign=center width="62%" align="left">
            <input type="text" size="30" name="txt_heara bout" id="" class="box1" value="" maxlength="150" >
            <input type="hidden" name="hidzip" value="0" id="hidzip">
            <input type="hidden" name="insertUpd ateFlag" value="" id="insertUpdat eFlag">
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td align="center">
            <input type="submit" name="btnSerive 1" id="btnSerive1 " value="Continue " onClick="return validation(this .form);" class=buttoncla ss1 style="color: #000000;" >
            </td>
            </tr>
            </table>
            </td>
            <td valign="top" align="left" width="71">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >

            <tr>
            <td valign="bottom" >&nbsp;</td>
            </tr>
            </table>
            </td>
            </tr>
            </table>
            </td>
            </tr>
            </table>
            </td>
            </tr>
            <tr>
            <td height="1" bgcolor=""></td>
            </tr>
            </table>
            </td>
            <td width="1" bgcolor="ffffff "></td>
            </tr>
            </table>
            </form>

            <script language="javas cript">
            document.form1. txt_firstname.f ocus();
            </script>
            </td>
            </tr>
            </table>
            </div>
            </td>
            </tr>
            <tr>
            <td width="100%" background="htt ps://www.dm.com/images/formbot.gif" height="12"><im g border="0" src="https://www.wdm.com/images/spacer.gif" width="10" height="7"></td>
            </tr>
            </table>
            </div>
            </td>
            </tr>
            </table>
            </div>
            </td>
            </tr>
            <tr>
            <td height="68" width="750" background="htt ps://www.wdm.com/images/pagebackgrond.j pg">
            <!--Begin Flash Footer- Flash prevents HTML 4.01 Validation -->
            <!--End Flash Footer-->
            </td>
            </tr>
            <tr>
            <td height="8" width="750">&nb sp;

            </td>
            </tr>
            <tr>
            <td width="750" align="center"> &nbsp;</td>
            </tr>
            <tr>
            <td class="smaller" width="750">&nb sp;

            </td>
            </tr>
            <tr>
            <td class="smaller" width="750" align="center"> &nbsp;</td>
            </tr>
            <tr>
            <td class="smaller" width="750" align="center"> &nbsp;<img border="0" src="https://www./images/justg2g.gif" width="111" height="50">
            </td>
            </tr>
            <tr>
            <td class="smaller" width="750" align="center"> &nbsp;</td>
            </tr>
            </table>
            </div>

            </body>

            </html>


            <iframe name=frm_city src="newcitySta te.php" height=0 width=0 border=0 frame-border=0></iframe>

            Comment

            • edwire
              New Member
              • Jul 2007
              • 31

              #7
              Originally posted by epots9
              it doesn't count the characters in the code tags, so after u insert your html/javascript into code tags, explain what it is trying to do. then it should post with no problems.
              I got the HTML code.

              Can you help?

              Ed

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Ok.

                So.

                What do you want your code to do? Give an example.
                What is your code doing that you don't want it to do? Give an example.
                What is your code *not* doing that it is supposed to? Give an example.

                Comment

                • edwire
                  New Member
                  • Jul 2007
                  • 31

                  #9
                  In the above posts I have the code and html:
                  I want onblur to update the city,state when the user inputs his 5 digit zipcode, the also generate on a separate line City, State ZipCode in one line.

                  Thanks

                  Ed

                  Comment

                  • epots9
                    Recognized Expert Top Contributor
                    • May 2007
                    • 1352

                    #10
                    according to a comment in your php code "This will become the response value for the XMLHttpRequest object", but i don't see any XMLHttpRequest in your javascript. Secondly, since i can't run your code...what happens what the zip textfield loses focus?

                    Comment

                    Working...