Jump to content

Recommended Posts

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]
<?php
include('./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 ? :D

please
Link to comment
https://forums.phpfreaks.com/topic/8928-onclick-to-update-a-iframe-by-sql-query/
Share on other sites

[!--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?
Hi,,

maybe that one should do the job,,
[code]
<html>
<head>
<title>selecting,,</title>
<body>
<?php
// 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>");
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,,
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]
<?php
include('../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]
<?php
include_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....
  • 2 weeks later...
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,,
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.