Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox won't copy details from one table to another Javascript PHP Ajax
    primarykey
    data
    text
    <p><strong>Hi everyone</strong> i'm creating the <em>"Billing address" "Delivery address"</em> form. When someone fills out the billing address details and the delivery is the same, I would like to save a person to tick the box to populate the details.</p> <p>I tried to validate it with javascript and php which are on the same page above the form(not in the head tag) with no joy. </p> <p>*Script updates the database *, ajax doesn't get the echo from php which is another thing that I can not figure out. So I have a couple of issues , don't know, maybe something interferes on the page.</p> <p>I just want to get the idea of how it should work . </p> <p>When I hit "submit"- AJAX sends the variables to PHP, then PHP updates database and echos the string, which is passed back to AJAX. But AJAX can't see it, the error strings I have in the AJAX code are not displayed, the only one that displays is "Some error occured " (I even changed it for "successfully updated" at some stage cause the database is updated:))</p> <p>Any help would be very much appreciated</p> <p>Page called myaccount.php</p> <pre><code> &lt;?php // AJAX CALLS THIS CODE TO EXECUTE if(isset($_POST['p'])||isset($_POST['a1'])||isset($_POST['a2'])||isset($_POST['c'])||isset($_POST['co'])||isset($_POST['con'])||isset($_POST['da1'])||isset($_POST['da2'])||isset($_POST['dc'])||isset($_POST['dco'])||isset($_POST['addcheckbox'])){ require_once('./includes/mysql_connect.php'); $p = mysql_real_escape_string(trim($_POST['p'])); $a1 = mysql_real_escape_string(trim($_POST['a1'])); $a2 = mysql_real_escape_string(trim($_POST['a2'])); $c = mysql_real_escape_string(trim($_POST['c'])); $co = mysql_real_escape_string(trim($_POST['co'])); $da1 = mysql_real_escape_string(trim($_POST['da1'])); $da2 = mysql_real_escape_string(trim($_POST['da2'])); $dc = mysql_real_escape_string(trim($_POST['dc'])); $dco = mysql_real_escape_string(trim($_POST['dco'])); if(isset($_POST['addcheckbox'])=='ticked'){ $da1 = mysql_real_escape_string(trim($_POST['a1'])); $da2 = mysql_real_escape_string(trim($_POST['a2'])); $dc = mysql_real_escape_string(trim($_POST['c'])); $dco = mysql_real_escape_string(trim($_POST['co'])); } $sql = "UPDATE customers SET address_1='$a1', address_2='$a2', phone='$p', city='$c', county='$co', country='$con', del_ad_1='$da1', del_ad_2='$da2', del_city='$dc', del_county='$dco' WHERE id_cust='$id'"; $query = mysql_query($sql); if(!$query){ echo 'success'; exit(); }else{ echo 'not_updated'; exit(); } } ?&gt; </code></pre> <p>this is the javascript</p> <pre><code> &lt;script type="text/javascript" language="javascript"&gt; function changeaddress(){ var p = _("phone").value; var a1 = _("address_1").value; var a2 = _("address_2").value; var c = _("city").value; var co = _("county").value; var con = _("country").value; var da1 = _("deladdress_1").value; var da2 = _("deladdress_2").value; var dc = _("delcity").value; var dco = _("delcounty").value; //checkbox if(document.getElementsById("addcheckbox").checked){ var da1 = a1; var da2 = a2; var dc = c; var dco = co; }else{ var da1 = _("deladdress_1").value; var da2 = _("deladdress_2").value; var dc = _("delcity").value; var dco = _("delcounty").value;} //ajax call if((p!=""||p=="") &amp;&amp; (a1!="") &amp;&amp; (a2!=""||a2=="") &amp;&amp; (c!="") &amp;&amp; (co!="")){ //_("changeaddbtn").style.display = "none"; _("status").innerHTML = 'updating your details ...'; var ajax = ajaxObj("POST", "/myaccount.php"); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) == true) { var response = ajax.responseText; if(response == 'success'){ _("changeaddressform").innerHTML = '&lt;h3&gt;Address is updated, check the first tab!!&lt;/p&gt;'; } else if (response == 'not_updated'){ _("status").innerHTML = "An error occured , the details were not updated!"; } else { _("status").innerHTML = "Some error occured!"; } }else{ _("status").innerHTML = "loading...";} } ajax.send("p="+p+"&amp;a1="+a1+"&amp;a2="+a2+"&amp;c="+c+"&amp;co="+co+"&amp;da1="+da1+"&amp;da2="+da2+"&amp;dc="+dc+"&amp;dco="+dco) ; } } &lt;/script&gt; </code></pre> <p>this is the Billingpart</p> <pre><code> Address* -------------------- &lt;input class="input_field" type="text" size="40" id="address_1" name="address_1" value="&lt;?php echo ''.$get_row['address_1'].''; ?&gt;"/&gt; Address ---------------------- &lt;input class="input_field" type="text" size="40" id="address_2" name="address_2" value="&lt;?php echo ''.$get_row['address_2'].' '; ?&gt;"/&gt; City/Town* &lt;input class="input_field" type="text" size="40" id="city" name="city" value="&lt;?php echo ''.$get_row['city'].' '; ?&gt;"/&gt; County* ----------------------- &lt;input class="input_field" type="text" size="40" id="county" name="county" value="&lt;?php echo ''.$get_row['county'].' '; ?&gt;"/&gt; &lt;p&gt;&lt;button id="changeaddbtn" class="submit_btn" onclick="changeaddress()" &gt;Submit Changes&lt;/button&gt; </code></pre> <p>Delivery</p> <pre><code>&lt;input type="checkbox" name="addcheckbox" id="addcheckbox" value="ticked" /&gt; Same as billing &lt;/p&gt; </code></pre> <p>"/></p> <pre><code> Address ------------------------------- &lt;input class="input_field" type="text" size="40" id="deladdress_2" value="&lt;?php echo ''.$get_row['del_ad_2'].' '; ?&gt;"/&gt; City/Town* ------------------------- &lt;input class="input_field" type="text" size="40" id="delcity" value="&lt;?php echo ''.$get_row['del_city'].' '; ?&gt;"/&gt; County* ------------- &lt;input class="input_field" type="text" size="40" id="delcounty" value="&lt;?php echo ''.$get_row['del_county'].' '; ?&gt;"/&gt; ----------------------------------------------- &lt;p&gt;&lt;button id="changeaddbtn" class="submit_btn" onclick="changeaddress()" &gt;Submit Changes&lt;/button&gt;&lt;/p&gt; &lt;p id="status"&gt;&lt;/p&gt; &lt;p id="status1"&gt;&lt;/p&gt; &lt;p id="status2"&gt;&lt;/p&gt; &lt;p id="status3"&gt;&lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload