ichversuchte Posted May 3, 2006 Share Posted May 3, 2006 I am trying to update a I frame when a person chooses a name from a combobox.I have this so far, which populates the combobox :[code]<?phpinclude('./Scripts/conn/cid.php'); $sql = "SELECT ra_name FROM staff_elkin ORDER BY ra_name ASC"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error());if (mysql_num_rows($result) > 0) { echo '<select name="raname" id="raname">';while ($row = mysql_fetch_array($result)) { $title = $row['ra_name']; echo("<option value='$title'>$title</option>"); } echo '</select>'; } include('./Scripts/close/end.php');?>[/code]From here I want to update a iframe, and i have no experience with iframes. I want to use one because I don't want to refresh the page. When they select a name, I want the I frame to be updated. I am goign to run a simple sql statement that pulls the names from that query.Can someone help me get started ? :Dplease Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/ Share on other sites More sharing options...
ichversuchte Posted May 3, 2006 Author Share Posted May 3, 2006 I have been reading and figured out iframes. Is it possible to to use the onclick with a combobox withouta button. I want to post with the click on the mouse on the comboox not a button. Please help Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-32832 Share on other sites More sharing options...
ichversuchte Posted May 3, 2006 Author Share Posted May 3, 2006 If no one can help me, can someone at least point me to a site or reference a book that can help me.Thank you Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-32940 Share on other sites More sharing options...
ober Posted May 3, 2006 Share Posted May 3, 2006 This has turned into a Javascript question. You can use the onchange event instead of onclick to fire a function from the selection in a select box.I'm moving this to Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-33009 Share on other sites More sharing options...
ichversuchte Posted May 3, 2006 Author Share Posted May 3, 2006 [!--quoteo(post=370957:date=May 3 2006, 01:14 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 3 2006, 01:14 PM) [snapback]370957[/snapback][/div][div class=\'quotemain\'][!--quotec--]This has turned into a Javascript question. You can use the onchange event instead of onclick to fire a function from the selection in a select box.I'm moving this to Javascript.[/quote]Can someone help me with this javascript question? Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-33043 Share on other sites More sharing options...
GBS Posted May 3, 2006 Share Posted May 3, 2006 Hi,,maybe that one should do the job,,[code]<html><head><title>selecting,,</title><body><?php// we populate the select objectecho '<select name="raname" id="raname" onchange=Change_Iframe_Contents(this)>';echo("<option value='0' selected>choose a title</option>");for ($i=1;$i<4;$i++) { echo("<option value=\"$i\">my page nb $i</option>"); }echo '</select>';?><iframe id="testing" src="script1.html" width=600 height=200>If you can see this, your browser doesn't understand IFRAME</iframe><script>function Change_Iframe_Contents(node) // change the iframe contents{if (node.value==1) { document.getElementById('testing').src="script1.html"; }if (node.value==2) { document.getElementById('testing').src="script2.html"; }if (node.value==3) { document.getElementById('testing').src="script3.html"; }}// brrrr,, firefox needs that line to init the select object ?!?!document.getElementById('raname').selectedIndex="0";</script></body></html>[/code]hoping it helps,,l8tr,, Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-33134 Share on other sites More sharing options...
ichversuchte Posted May 6, 2006 Author Share Posted May 6, 2006 I am new to javascript and for some reason i am having trouble implementing this. I tried using the code above and i created the three documents script1.html, script2.html, script3.html.I need to use this code which fills the combobox :[code]<?phpinclude('../Scripts/conn/cid.php'); $sql = "SELECT ra_name FROM staff_elkin ORDER BY ra_name ASC"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error());if (mysql_num_rows($result) > 0) { '<select name="raname" id="raname" onchange=Change_Iframe_Contents(this)>';while ($row = mysql_fetch_array($result)) { $title = $row['ra_name']; echo("<option value='$title'>$title</option>"); } echo '</select>'; } include('../Scripts/close/end.php');?>[/code]I need to take the combobox on a onchange and update the iframe. Depending on the choice which is [code] $title [/code] i need to update the iframe after running that varible through this sql statement - [code] <?phpinclude_once('conn/conn.php');$query = "SELECT raname1, raname2, date1, raname3, date2 FROM dutyswitch_elkin where raname1 = '".$title."'"; $result = mysql_query($query) or die('Error, query failed');echo '<table border="0">';while(list($raname1, $raname2, $date1, $raname3, $date2, ) = mysql_fetch_array($result)){echo "<tr><td>$raname1 <em>made the request:</em> <br>$raname2 <em>will sit on</em> $date1 <em>and</em> </br>$raname3 <em>will sit on</em> $date2</td></tr>";}echo '</table>';echo '<br>';?>[/code]I have been trying to get this work for a while. I have a couple of books but I can't seem to figure out. Can someone please help me. I don't need it done for me, but can someone please direct me. Thank you for your help in advance.... Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-33788 Share on other sites More sharing options...
GBS Posted May 16, 2006 Share Posted May 16, 2006 Hi,,If I get it,, this only can be done using Ajax/JPSpan/XMLHttpRequest methods, (they are quite the same, I guess,,)Take this as example,... your main file could be:[code]<html><head><title>selecting,,</title></head><body><?php//TODO: your database connexion$sql = "SELECT ra_name FROM staff_elkin ORDER BY ra_name ASC";$result = mysql_query($sql) or die('Query failed. ' . mysql_error());if (mysql_num_rows($result) > 0){// we populate the select object echo '<select name="raname" id="raname" onchange=Change_Iframe_Contents(this)>'; echo("<option value='0' selected>choose a title</option>"); while ($row = mysql_fetch_array($result)) { $title = $row['ra_name']; echo("<option value='$title'>$title</option>"); } echo '</select>'; }mysql_close($db_link);?><div id="testing" align="center" width=600 height=200></div><script>/* Ajax/XMLHttpRequest part : */var req;function Change_Iframe_Contents(node) // change the iframe contents{ if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } else { return false; } req.onreadystatechange = processRequest; req.open("POST", "table.php", true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var tosend="title="+document.getElementById('raname').value; req.send(tosend);}function processRequest(){ if (req.readyState == 4) { if (req.status == 200) { document.getElementById('testing').innerHTML = req.responseText; } }}// brrrr,, firefox needs that line to init the select object ?!?!document.getElementById('raname').selectedIndex="0";</script></body></html>[/code]& the data.php file could be:[code]<?php$title=$_POST['title'];//TODO: your database connexion$query = "SELECT raname1, raname2, date1, raname3, date2 FROM dutyswitch_elkin where raname1 = '".$title."'"; $result = mysql_query($query) or die('Error, query failed');$table = '<table border="0">';while(list($raname1, $raname2, $date1, $raname3, $date2, ) = mysql_fetch_array($result)){$table = $table."<tr><td>$raname1 <em>made the request:</em> <br>$raname2 <em>will sit on</em> $date1 <em>and</em> </br>$raname3 <em>will sit on</em> $date2</td></tr>";}$table = $table.'</table>';$table = $table.'<br>';mysql_close($db_link);echo $table;?>[/code]So, you don't need anymore to use an iframe,... Ajax does the job :)Hoping it helps,,l8tr,, Quote Link to comment https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/#findComment-36206 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.