giv3mesmile Posted July 1, 2010 Share Posted July 1, 2010 In my site, i have FAQ, and answers...i imaginated it.... there are two boxes, one witch is constant and includes questions, and the other that will display the answer ( Right one in the image ) So, what I need is, when user clicks on the question ( left side on the image ), the answer text popup in the right box... any clues of how to do it? I've asked this before , but didnt get a propper answer, and i really need it now thanks in advanced... [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
radar Posted July 12, 2010 Share Posted July 12, 2010 Well, this you would want to do in javascript probably... The easiest and most simple way would be to use PHP to query a mySQL database to get the answer for the specific question clicked... Then in the link you would put like: OnClick="GetQuestion('fetch.php?id=1') return false;" Then of course you would have your right side with a div or something along those lines with an ID in it for javascript to read and modify the innerHTML of. And of course creating the fetch.php to fetch the information from the mySQL database. hope it gets you on your way... Just to help get you started, I wrote your javascript ajax calls for you. function AjaxObjectCreateGeneral() { var req; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari req = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } return req; } function changeAnswer(url) { req=AjaxObjectCreateGeneral(); if(req) { var myRand = parseInt(Math.random()*99999999); var url = url; var srcs = url+"&int="+myRand; $('TransMsgDisplay').innerHTML='Querying Database'; req.onreadystatechange = processFetch; req.open("GET",srcs,true); req.send(); } } function processFetch() { if(req.readyState == 4) { if(req.status == 200) { if(req.responseText == 0) { document.location.href="index.php"; } else { document.getElementById("TransMsgDisplay").innerHTML=req.responseText; } } } } This would either be directly in the HTML page, or added in from a seperate file. Again hope it helps you on your way. 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.