Heinz Stapff Posted August 3, 2011 Report Share Posted August 3, 2011 I found this at w3 schools PHP tutorial but see it represents a Select html box and options and my site has UL, List/Li Elements that had < a tags with href and target attributes. I've stripped the jewelry UL of it's Li < a tags and want to know how to get the Li oncklick to get the database table to change the 'f1' div innerHTML. w3 Schoolhttp://www.w3schools.com/php/php_ajax_database.asp The function function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } I have addEvent in mockup.js like so var jewelrylist=document.getElementById('jewelrylist'); var jewelry=jewelrylist.getElementsByTagName('li'); var silver=jewelry.item(1); function getsilver(text)//Changed from 'str' { if (silver.text=="Silver")//the li element text { document.getElementById("f1").innerHTML="";//the div id I want to change return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("f1").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getSilver.php?s="+str,true);//don't know if this file goes in the www folder? xmlhttp.send(); } addEvent(silver,'click', getsilver(); }, false);//Should work?? My HTML UL ID jewelrylist <ul id="jewelrylist"> <li id="jewelry" class="top" title="The Most Beautiful Jewelry Made in Mexico!">Jewelry</li> <li class="item" title="Silver Jewelry Made in Mexico!">Silver</li> <li class="item" title="Silver & Gold Jewelry, Made in Mexico!">Silver & Gold</li> <li class="item" title="Silver Jewelry with Stones, Made in Mexico!">Silver & Stones</a> </li> </ul> getSilver.php Not sure what folder to put this in, www or php? <?php $s=$_GET["s"]; $con=mysql_connectmysql_connect('localhost','root','root');//default for Uniserver?? if(!con){die('Not connected:'.mysql_error( ));} mysql_select_db("wbi",$con);//mydb $sql="SELECT*FROM silver WHERE Id='".$s."'";//table silver has 2 test rows $result=mysql_query($sql); while($row = mysql_fetch_array($result))//might have to add some splits for Set types in rows? { echo "<div id='rowcell" . $row['Id'] . "' class='rowcell'>"; echo "<div id='imagecell" . $row['Id'] . "' class='imagecell' align='center'>"; echo "<a id='imageref" . $row['Id'] . "' class='imageref'"; echo "href='" . $row['Href'] . "' title='Take a Closer Look then Press Your"; echo "Back Button to Return'><img src='" . $row['Src'] . "'/></a></div>"; #end of .imagecell continues verbosley I know I'll have to use INCLUDE mydb.php and filtering to make it more secure but I'd like to get it tried before I start modifying the other ULs. Any advise greatly appreciated. Also let me know if this is an inappropriate forum for this topic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.