mark110384 Posted September 29, 2008 Share Posted September 29, 2008 Hey guys I been developing an AJAX portion of my website and I'm nearly there but I have come across a problem, I have 2 DIVs, one that displays the item number and name when the request is sent and another that is populated when the user selects the item, this includes a price and description. How would I send variables from my php script that aren't in the echo string to populate the second DIV? Hope it makes sense the Coding is as follows. Thanks JS //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support this function!"); } } //Our XmlHttpRequest object to get the auto suggest var searchReq = getXmlHttpRequestObject(); //Called from keyup on the search textbox. //Starts the AJAX request. function searchSuggest() { //Check if the search field is empty. If so empty Search Suggest inner HTML. if (document.getElementById('txtSearch').value == "") { document.getElementById('search_suggest').innerHTML = ''; } else if (searchReq.readyState == 4 || searchReq.readyState == 0) { var str = escape(document.getElementById('txtSearch').value); searchReq.open("GET", 'searchSuggest.php?search=' + str+'&sid='+Math.random(), true); searchReq.onreadystatechange = handleSearchSuggest; searchReq.send(null); } } //Called when the AJAX response is returned. function handleSearchSuggest() { if (searchReq.readyState == 4) { var ss = document.getElementById('search_suggest') ss.innerHTML = ''; var str = searchReq.responseText.split("\n"); for(i=0; i < str.length - 1; i++) { var suggest = '<div onmouseover="javascript:suggestOver(this);" '; suggest += 'onmouseout="javascript:suggestOut(this);" '; suggest += 'onclick="javascript:setSearch(this.innerHTML);" '; suggest += 'class="suggest_link">' + str[i] + '</div>'; ss.innerHTML += suggest; } } } //Mouse over function function suggestOver(div_value) { div_value.className = 'suggest_link_over'; } //Mouse out function function suggestOut(div_value) { div_value.className = 'suggest_link'; } //Click function function setSearch(value) { document.getElementById('chart_info').innerHTML = value + "Price:" + ("<? echo $price; ?>"); } PHP <? require('../functions.php'); $connect = @ConnectToAgents($dbhost, $dbuser, $dbname); $search = $_GET['search']; $pubtype = 'Chart'; $sql = "SELECT * FROM products WHERE (Code LIKE '%" . $search . "%' OR Description LIKE '%" . $search . "%') AND Type = '$pubtype' limit 0,20"; $result = mysql_query($sql); while($myrow = mysql_fetch_array($result)) { $chartcode = $myrow['Code']; $chartp = $myrow['PPost']; $chartdescription = $myrow['Description']; $price = $myrow['Price']; echo "$chartcode $chartp - $chartdescription \n"; } ?> Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted September 30, 2008 Share Posted September 30, 2008 you can echo javascript code along with your other stuff you're sending back. use this javascript code to modify the second div. that might help. are you sending back all the information at once? Quote Link to comment Share on other sites More sharing options...
bluebutterflyofyourmind Posted September 30, 2008 Share Posted September 30, 2008 as i see now....don't submit multiple threads on the same topic. bump the old one up if you still need help. 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.