Jump to content

sirup_segar

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sirup_segar's Achievements

Member

Member (2/5)

0

Reputation

  1. hi, after i read php ajax responseXML from w3schools.com, i'd like to try it myself. so i copy-paste the code and have it run from my computer. i use xampp and php5. function showUser(str) { var xmlHttp; xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="responsexml.php" url=url+"?q="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { xmlDoc=xmlHttp.responseXML; document.getElementById("firstname").innerHTML= xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue; document.getElementById("lastname").innerHTML= xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue; document.getElementById("job").innerHTML= xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue; document.getElementById("age_text").innerHTML="Age: "; document.getElementById("age").innerHTML= xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue; document.getElementById("hometown_text").innerHTML="<br/>From: "; document.getElementById("hometown").innerHTML= xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue; } } xmlHttp.open("GET",url,true) xmlHttp.send(null) } function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } and i got error message on my firefox, xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue has no properties i'm not familiar with xml, so first i'm confuse in where to post this thread, in ajax room,or else. anyway, this is the php code <?php header('Content-Type: text/xml'); header("Cache-Control: no-cache, must-revalidate"); //A date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); $q=$_GET["q"]; $con = mysql_connect('localhost', 'peter', 'abc123'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ajax_demo", $con); $sql="SELECT * FROM user WHERE id = ".$q.""; $result = mysql_query($sql); echo '<?xml version="1.0" encoding="ISO-8859-1"?> <person>'; while($row = mysql_fetch_array($result)) { echo "<firstname>" . $row['FirstName'] . "</firstname>"; echo "<lastname>" . $row['LastName'] . "</lastname>"; echo "<age>" . $row['Age'] . "</age>"; echo "<hometown>" . $row['Hometown'] . "</hometown>"; echo "<job>" . $row['Job'] . "</job>"; } echo "</person>"; mysql_close($con); ?> thanks in advance..
  2. sorry mr rajiv, i did it again.. this is my cekqty() function cekqty() { var jml=document.getElementById("max_isbnx").value; for (i=0;i<jml;i++) { var qty=document.getElementById("txt_qty["+i+"]").value; if ((qty<0) || (isNaN(qty)==true)) { alert("Periksa Kembali Inputan Jumlah Buku"); return false; exit; } } return true; } and this is my form <table align='center' width='650' class='mytable'> <tr> <form method='post' action='shop_action.php' name='frmshopaction' onSubmit='return cekqty()'> <td align=center><b>ISBN</b></td> <td align=center><b>Judul</b></td> <td align=center><b>Penerbit</b></td> <td align=center><b>Pengarang</b></td> <td align=center><b>Harga Satuan</b></td> <td align=center><b>Qty</b></td> <td align=center><b>Harga</b></td> </tr> "; $jml=0; $price=0; for ($i=0;$i<$hitung;$i++) { $jml=$jml+$qtyx[$i]; $price=$price+$hrg_qtyx[$i]; } for ($i=0;$i<$hitung;$i++) { $tmpisbn=$isbnx[$i]; $tmpjdul=htmlspecialchars($judulx[$i]); $tmppen=$penerbitx[$i]; $tmppeng=htmlspecialchars($pengarangx[$i]); $tmpqty=$qtyx[$i]; $tmphrg=$hrgx[$i]; $tmphrgtot=$hrg_qtyx[$i]; $hrgrp=tampilrupiah($tmphrg); $hrgtot=tampilrupiah($tmphrgtot); $pricerp=tampilrupiah($price); echo "<tr> <td>$tmpisbn</td> <td>$tmpjdul</td> <td>$tmppen</td> <td>$tmppeng</td> <td>$hrgrp</td> <td><input type='text' name='txt_qty[$i]' id='txt_qty[$i]' value='$tmpqty' size='1'></td> <td>$hrgtot</td> </tr> "; } echo "<tr> <td colspan=8><div class='batalbeli'>Total Barang : <b>$jml</b> ‚ Total Harga : <b>$pricerp</b></div></td> </tr> </table>"; echo "<table align='center'> <tr> <td colspan='3'> <div class='batalbeli'>Untuk membatalkan barang, masukkan angka 0 pada jumlah barang</div> </td> </tr> <tr> <td align='center'> <input type='hidden' id='max_isbnx' value='$hitung'> <input type='image' src='../image/update-qty.gif' height='40' width='150' name='editshop' onClick='cekqty()'> </form> thanks in advance..
  3. mr rajiv,i've solved the problem with my error. i change my code from var qty=document.getElementById("txt_qty"+i); into var qty=document.getElementById("txt_qty["+i+"]").value; and it works, the error dissapear. but another problem come. when i click the submit image <input type='image' src='../image/update-qty.gif' height='40' width='150' name='editshop' onClick='cekqty()'> my form is submitted twice,not only once? so when i try to enter a negative number or non numeric char, the error message from cekqty() displayed twice. ??? thanks a lot..
  4. mr rajiv, thanks for your attention. i've changed my code like you suggest me. function cekqty() { var jml=document.getElementById("max_isbnx").value; for (i=0;i<jml;i++) { var qty=document.getElementById("txt_qty"+i); if ((qty.value<0) || (qty.length==0) || (isNaN(qty)==true)) { alert("Check Your Book Quantity"); return false; } else { return true; } } } anyway, i've changed my form <form method='post' action='shop_action.php' name='frmshopaction' onSubmit='return cekqty()'> apparently the same error message still appear. ???
  5. wow,thanks a lot mr rajiv, that really helps me..cheers..
  6. mr rajiv, how do i put double quotes on my form? because i use echo ""; to display my form. so i change all the double quotes into single quotes..should i change it all? :'(
  7. sorry mr vicodin and mr rajivgonsalves this is my form <form action='shop_additem.php' method='get' name='frmbeli' onSubmit='return cekbeli()'> <table align='right'> <tr> <td> <input type='hidden' name='idisbn' value='$row[1]'> <input type='hidden' name='juduly' value='$judul'> <input type='hidden' name='hargay' value='$tmpharga'> <input type='hidden' name='penerbity' value='$penerbit'> <input type='hidden' name='pengarangy' value='$pengarang'> Jumlah <input type='text' size='1' name='jmlbrgy' maxlength='4'> </td> <td> <input name='submit' type='submit' value='Beli'> </td> </tr> </table> </form> and this is my shop_additem.php if ($jmlbrgy>0) { $isbnx[]=$idisbn; $judulx[]=$juduly; $penerbitx[]=$penerbity; $pengarangx[]=$pengarangy; $qtyx[]=trim($jmlbrgy); $hrgx[]=$hargay; $hrg_qtyx[]=$jmlbrgy*$hargay; } @ mr mmarif4u, my two variables are taken from $penerbit and $pengarang. @mr themistral, i have tried to use addslashes in front of $juduly and $pengarangy on the top of my shop_additem.php. but i got the same result, remaining chars behind apostrophes were still dissapear.. ??? lots of thanks for ur attention..
  8. hi..please give me an advice.. { $judulx[]=$juduly; $pengarangx[]=$pengarangy; } before the form was submitted, the content of $juduly and $pengarangy were "jail house's rock" and "amina ana'akira" respectively. but why after the form was submitted, the variable have changed to "jail house" and "amina ana"? was there something important that i forget? thanks in advance..
  9. hi, still working on my last thread, i found that when i click one of my submit image, <input type='image' src='../image/lihat-katalog.gif' width='150' height='40' name='lihatkat'> <input type='image' src='../image/update-qty.gif' height='40' width='150' name='editshop' onClick='cekqty($count)'> <input type='image' src='../image/selesai-belanja.gif' width='150' height='40' name='cekout'> the same error displayed,just like when i click the <input type='image' src='../image/update-qty.gif' height='40' width='150' name='editshop' onClick='cekqty($count)'> anyway, thanks for your attention..
  10. hi,i've been searching in this forum about my error, but still can't find it out.i try to use regexp to validate number only. function cekqty(n) { var regcek=new RegExp(/^[0-9]+$/); for (i=0;i<n;i++) { var qty=document.getElementById("txt_qty"+i); var qty_ck=qty.value; if ((qty_ck<0) || (qty_ck.length==0) || (qty_ck.search(regcek)<0)) { alert("Check Your Book Quantity"); return false; } else { return true; } } } my form code is : <form method='post' action='shop_action.php' name='frmshopaction' onSubmit='return cekqty($count)'> my td code is : <td><input type='text' name='txt_qty[$i]' id='txt_qty[$i]' value='$tmpqty' size='1'></td> and my submit image is: <input type='hidden' id='max_isbnx' value='$count'> <input type='image' src='../image/update-qty.gif' height='40' width='150' name='editshop' onClick='cekqty($count)'> when i click the image, the error is "object required on line 44 char 3", that is on the "return false" statement. also, the error message displays twice, not only once,with the same error message. lots lots thanks for your help...
  11. i think i'll put "Topics Solved" now..hehe thanks for everyone..
  12. ehmm, by the way again, can we use use multiple header("Location:some_location.php") in some if-else syntax?so there aren't error Warning: Cannot add header information - headers already sent by ? thanks again...i'll give "topics solved" after this thread... thanks;D
  13. for mr PFMaBiSmAd, sorry the answer is no,i didn't change back my form method to post. but i have now, and it worked.thanks a lot. for mr mmarif4u, thanks for the snippet..it's because i haven't change back the method into post.. . by the way, how can i add the "topic solved" flag to my thread??
  14. mr mmarif4u,i have changed my code if (isset($_POST["edit_x"])) { echo "<script language='javascript'> alert('you are edited'); </script>"; } but nothing shows up when i click on the edit image... ???
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.