[SOLVED] <iframe> question
Moderator: General Moderators
- Think Pink
- Forum Contributor
- Posts: 106
- Joined: Mon Aug 02, 2004 3:29 pm
<iframe> question
hy. need some help pls.
i have index.php and page_2.php.
on index.php i have a dropdown (name=country) and a <iframe> with page_2.php loading in it. The page page_2.php has also a dropdown (name=cities).
When i choose a country in index.php, it loads in the dropdown from the <iframe > the corresponding cities.
The question is how I take selected value from dropdown loaded in the <iframe> and insert it in a $db.?
thx in advance
i have index.php and page_2.php.
on index.php i have a dropdown (name=country) and a <iframe> with page_2.php loading in it. The page page_2.php has also a dropdown (name=cities).
When i choose a country in index.php, it loads in the dropdown from the <iframe > the corresponding cities.
The question is how I take selected value from dropdown loaded in the <iframe> and insert it in a $db.?
thx in advance
- Think Pink
- Forum Contributor
- Posts: 106
- Joined: Mon Aug 02, 2004 3:29 pm
<iframe> question
my main page remains. Only the <iframe> refreshes. I use the <iframe> because is too complicated for me to make a dynamic dropdown with javascript, so the <iframe> size is not bigger than the drop down
Put the drop down in a form and submit the form using the onChange javascript function. In the action of the form set it as follows:
Code: Select all
<form action="" method="post" name="form1" target="_self">- Think Pink
- Forum Contributor
- Posts: 106
- Joined: Mon Aug 02, 2004 3:29 pm
you mean like this?
index.php
iframe.php
index.php
Code: Select all
<?php
// connection information
?>Code: Select all
<table align="center" width="100" cellspacing="0" cellpadding="0" border="1">
<form name="test" method="post" action="<? $PHP_SELF; ?>" >
<tr><td width="100" align="center" valign="middle" height="35">
<select id="selCountry" name="selCountry" onChange="parent.content.location.href=iframe.php?selCountry='+document.getElementById('selCountry').value"><option selected value="0">Select One</option>Code: Select all
<?php
$sql = "SELECT id_Country, nume_Country FROM Country ORDER BY nume_Country ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_Country']."'>".$row['nume_Country']."</option>";
}
?>Code: Select all
</select></td></tr>
<tr><td width="100" align="center" valign="middle" height="35">frame here
<iframe src="iframe.php" name="content" width="150" height="30" marginwidth="0" marginheight="0" hspace="4" vspace="4" align="middle" scrolling="no" frameborder="0"></iframe>
</td></tr>
<tr><td>
<input type="text" name="message">
</td></tr>
<tr><td>
<input type="submit" name="adaugaOG">
</td></tr>
</form>
</table>
<table align="center" cellspacing="2" cellpadding="2" border="0"><tr><td align="center">Code: Select all
<?php
if(isset($_POST['adaugaOG'])) {
$sqlOG = "SELECT * FROM oferta_generala";
$resultOG = mysql_query($sqlOG);
$sqlOG = "INSERT INTO ogTbl(id_Country, id_City, transport) VALUES ('".$_POST['selCountry']."', '".$_POST['selJudet']."', '".$_POST['transport']."')";
mysql_query($sqlOG);
print '<span class="mesaj4"><LI> Country a fost adaugata cu succes !</span>';
exit;
}
?>Code: Select all
</td></tr></table>iframe.php
Code: Select all
<?php
// connection information
print "<select name="selJudet">";
<option selected value="">Alege City</option>
<?php
$id_Country = $_GET['selCountry'];
$sql = "SELECT id_City, nume_City FROM City WHERE id_Country = '".$id_Country."' ORDER BY nume_City ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
print "<option value='".$row['id_City']."'>".$row['nume_City']."</option>";
}
print "</select>";
?>UNTESTED....
OK, I think I know what your trying to do.
Add a hidden field in the form of your main page:
Replace your current submit button whith this one:
Add the following Javascript function to the top of the main page:
Replace your current IFRAME code with the following:
This is untested but it should work. Also, I made some changes to how you print strings in php.
You can't print a string by doing the following:
OK, I think I know what your trying to do.
Add a hidden field in the form of your main page:
Code: Select all
<form name="test" method="post" action="<? $PHP_SELF; ?>" >
<!-- HIDDEN FIELD -->
<input type="hidden" name="hidden_city">Code: Select all
<input type="submit" name="adaugaOG" onClick="submitForm();return false;">Code: Select all
function submitForm(){
document.test.hidden_city.value = parent.content.document.iframeform.selJudet.value;
document.test.submit();
}Code: Select all
<?php
echo '<form action="" method="get" name="iframeform">';
echo '<select name="selJudet">';
echo '<option selected value="">Alege City</option> ';
$id_Country = $_GET['selCountry'];
$sql = "SELECT id_City, nume_City FROM City WHERE id_Country = '".$id_Country."' ORDER BY nume_City ASC";
$resursa = mysql_query($sql);
while($row = mysql_fetch_array($resursa))
{
echo '<option value="'.$row['id_City'].'">'.$row['nume_City'].'</option>';
}
echo '</select>';
echo '</form>';
?>You can't print a string by doing the following:
It should look like this:Code: Select all
<?php print "<select name="selJudet">"; ?>
Code: Select all
<?php
print "<select name="selJudet">";
//or
print '<select name="selJudet">';
//or
echo "<select name="selJudet">";
//or
echo '<select name="selJudet">';
//or
?>- Think Pink
- Forum Contributor
- Posts: 106
- Joined: Mon Aug 02, 2004 3:29 pm
<iframe> question
not working. now, not even the country name is aded to the $db.
I really don't get this. Some how I see the solution in my head, but it just doesnt work. And I have the same problem with double combos that are in the same page.
in dropdown 1 I chhose country, with an onchange event the page is submited, in dropdown 2 coresponded cities are shown. But now the problem comes with the first dropdown. After the page is submited (to load the second dropdown) the first option selected should be the country I just selected, but appears the first thing that is first in the list.
maybe you could help me with that, and i'll seee later about the other problem with the <iframe>.
I really don't get this. Some how I see the solution in my head, but it just doesnt work. And I have the same problem with double combos that are in the same page.
in dropdown 1 I chhose country, with an onchange event the page is submited, in dropdown 2 coresponded cities are shown. But now the problem comes with the first dropdown. After the page is submited (to load the second dropdown) the first option selected should be the country I just selected, but appears the first thing that is first in the list.
maybe you could help me with that, and i'll seee later about the other problem with the <iframe>.
- Think Pink
- Forum Contributor
- Posts: 106
- Joined: Mon Aug 02, 2004 3:29 pm