Jump to content


Photo

onclick to update a iframe by sql query


  • Please log in to reply
7 replies to this topic

#1 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 May 2006 - 12:19 AM

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 :
<?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');
?>



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

#2 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 May 2006 - 02:49 AM

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

#3 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 May 2006 - 02:05 PM

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

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 03 May 2006 - 05:14 PM

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.

Info: PHP Manual


#5 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 03 May 2006 - 06:22 PM

[!--quoteo(post=370957:date=May 3 2006, 01:14 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 3 2006, 01:14 PM) View Post[/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?

#6 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 03 May 2006 - 09:22 PM

Hi,,

maybe that one should do the job,,
<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>

hoping it helps,,

l8tr,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)

#7 ichversuchte

ichversuchte
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 06 May 2006 - 04:39 AM

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 :

<?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');
?>


I need to take the combobox on a onchange and update the iframe. Depending on the choice which is
$title
i need to update the iframe after running that varible through this sql statement -
<?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>';
?>

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

#8 GBS

GBS
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 16 May 2006 - 12:29 PM

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:
<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>
& the data.php file could be:
<?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;
?>
So, you don't need anymore to use an iframe,... Ajax does the job :)
Hoping it helps,,

l8tr,,
Sorry for my english,... I do my best, but sometimes,...
1st intention: understand the problem
2nd intention: try to solve it
3rd intention: try to understand how to solve it :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users