|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
PHP-General - $_GET using an iframe
Alright, so I'm wondering if I'm doing something wrong or if this is not possible...
Basically I have a left nav folder tree broken down into states, counties, and cities. When a user clicks on a county, I want the right column of the site to have rotating images displayed. For the right column, I have created an iframe. For each of the tree items, they are all linked as such: Code:
<a href="#?county=$county" onclick="return false;">County</a> (Without the onclick="return false;" the folder tree breaks on refresh.) I have also tried without onclick="return false" For the iframe, I have the following code: Code:
$county = $_GET['county']; print $county; This displays nothing... but if I change the link to: Code:
<a href="getcounty.php?county=$county">County</a> It works properly. I have a Javascript script that will rotate images and that part works.. but I need it to only rotate images for the particular county. Any input would be appreciated... If you need further information, let me know. Thanks. |
|
#2
|
||||
|
||||
|
Nothing following an # sign in a URL is sent to the server, in order to send the variable to the server you will need to remove that.
Your description isn't that clear to me. What exactly needs to happen when you click on a link? Does it need to call a Javascript function? Does it need to change the address of the iframe? |
|
#3
|
||||
|
||||
|
Thanks for the reply
Quote:
Unfortunate... but good to know. Quote:
In the folder tree on the left, a user can click a state, county, or city. When they click one, the menu drops down. I am wanting to somehow pass the information to an iframe of what they currently clicked on. For example, if a user clicks on Alachua, I want Alachua passed over to the iframe. The iframe is where I have rotating banners displayed. However, I only want banners displayed for the county that has been clicked on. Because of this limitation, I need to somehow pass the county name over which is why I was trying with #?county=$county ... I don't want the entire page reloaded by linking to itself because then the folder tree will collapse entirely again. So trying to find another way of passing the variable. Whether a function is called, the address is changed, etc, doesn't really matter... as long as I can somehow get the county name over to the iframe. Thanks... |
|
#4
|
||||
|
||||
|
Try setting the A tag HREF attribute to the URL you want to load in the IFRAME, then use the TARGET attribute of the A tag to cause the URL to be loaded in the IFRAME.
|
|
#5
|
||||
|
||||
|
Quote:
I had considered that, but target is depracated, so was trying to stay away from that if possible... |
|
#6
|
|||
|
|||
|
Quote:
What if instead of an iframe, you used ajax to pull in a page with the javascript for the rotating banner? |
|
#7
|
||||
|
||||
|
Quote:
That would be awesome.... um.. how do I do that? ![]() I don't have to use an iframe... only using one because I thought it would be easy... (for me). I was wrong. My knowledge is limited in most programming areas... If you could point me in the right direction, that would be great! I'm doing this site for a friend and well... seem to have gotten myself in way over my head here... but I've learned quite a bit because of this site as well, so I'm not too upset. Thanks... |
|
#8
|
|||||
|
|||||
|
Probably the simplest thing would to be to use jQuery's ajax library if your not that comfortable with ajax.
But basically, when you handle the click for expanding the tree, also call a seperate javascript function that makes your ajax request and loads a div in place of your iframe. i.e. javascript Code:
Of course this is oversimplified, but you get the idea I think. You have a div with an id of bannerDiv and calling updateBannerAdd(county) would return the new html to place in that div for the new county. |
|
#9
|
||||
|
||||
|
Quote:
You could also change the src attribute of the iframe using Javascript in the onclick event for the A tag. You're more likely to run into compatibility issues with that though than with target. If your iframe currently has Javascript in it you will need to do a bit of re-arranging to make it work over AJAX. When you load data into the page using AJAX, any Javascript code that might be contained within the data is not executed as if it were loaded in an iframe. |
|
#10
|
||||
|
||||
|
Quote: Alright... so I seem to be doing something wrong.. or just missing something somewhere... I added the function above, have the link calling the function, created a div, and created the banner.php page to display the county, but nothing is being displayed... This is what I have taken the above function to mean... it takes $county and sends it via POST to yourbannerloader.php. From within yourbannerloader.php, I have tried pulling the post info via: $county = $_POST['county']; Then I tried displaying $county... and nothing is being displayed. Can you please help clarify... Thanks. |
|
#11
|
||||
|
||||
|
simple things first, the above example is using jQuery, so you would need to have that library loaded before the call to the function. Got this step? Just making sure.
Your synopsis of the function is correct, when called it should invoke an ajax request to yourbannerloader.php with the country argument being sent via post. |
|
#12
|
||||
|
||||
|
Quote:
Since the folder tree is using jQuery, I already have the library loaded... don't I? (Yes, you can talk to me like I'm a beginner). |
|
#13
|
||||
|
||||
|
Yes you should have the library loaded already.
Can you post your full code?
__________________
[read: PHP Security Guide | CSRF | PCRE Modifiers | Encryption | Form Processing | File Validation] [tools: PHPEd | PHP Docs | jQuery | CodeIgniter | Drupal | SwiftMailer | CKEditor | reCAPTCHA] |
|
#14
|
||||
|
||||
|
This is what populates the folder tree (left nav):
Code:
if (mysql_num_rows($result) != '0') {
while($row = mysql_fetch_array($result)) {
$string5= $row['string'];
$state3 = $row['state'];
$county3 = $row['county'];
$city3 = $row['city'];
$item3 = $row['item_name'];
if ($state2 != $state3) {
if ($i != 1) {
$treeview .= "</ul></li></ul></li></ul></li>";
}
$i++;
$treeview .= "<li class=\"expandable\"><div class=\"hitarea expandable-hitarea\"><a href=\"#\" style=\"margin-left:20px;\"onclick=\"return false;\">".$state3."</a></div><br />";
$state2 = $state3;
$j = 1;
}
if ($county2 != $county3) {
if ($j != 1) {
$treeview .= "</ul></li></ul></li></ul>";
}
$j++;
$treeview .= "<ul style=\"display:none;\">";
$treeview .= "<li class=\"expandable\"><div class=\"hitarea expandable-hitarea\"><a href=\"#\" style=\"margin-left:20px;\" onclick=\"updateBannerAdd(county); return false;\">".$county3."</a></div><br />";
$county2 = $county3;
}
if ($city2 != $city3) {
$treeview .= "<ul style=\"display:none;\">";
$treeview .= "<li class=\"expandable\"><div class=\"hitarea expandable-hitarea\"><a href=\"#\" style=\"margin-left:20px;\" onclick=\"return false;\">".$city3."</a></div><br />";
$city2 = $city3;
$treeview .= "<ul style=\"display:none;\">";
}
if ($item3) {
// $treeview .= "<li><a href=\"index.php\">".$item3."</a></li><br />";
$treeview .= "<li>".$item3."</li>";
$item2 = $item3;
}
}
}
$treeview .= "</ul></li></ul></li></ul></li></ul>";
All the javascript links and such: Code:
<link rel="stylesheet" href="./jquery.treeview.css" />
<link rel="stylesheet" href="./red-treeview.css" />
<link rel="stylesheet" href="screen.css" />
<link rel="stylesheet" href="um.css" type="text/css" />
<script src="./jquery.js" type="text/javascript"></script>
<script src="./jquery.cookie.js" type="text/javascript"></script>
<script src="./jquery.treeview.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#tree").treeview({
collapsed: true,
animated: "medium",
control:"#sidetreecontrol",
prerendered: true,
persist: "location"
});
})
</script>
<script type="text/javascript">
function updateBannerAdd(county) {
$.ajax({
type: "POST",
url: "banner.php",
data: "county="+county,
success: function(msg) {
$('#bannerDiv').html(msg);
}
});
}
</script>
The div: Code:
<div id="bannerDiv"></div> Banner.php Code:
<?php print $county; ?> I've also tried banner.php with $county = $_POST['county']; If you need the code from any of the .js or .css files, just let me know. Thanks. |
|
#15
|
||||
|
||||
|
should probably be
PHP Code:
You have to pass the specific county value to the javascript function, in your current incarnation, county is not set. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > PHP-General - $_GET using an iframe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|