Send a variable in a popup
Solved
boony
Posted messages
46
Status
Member
-
boony Posted messages 46 Status Member -
boony Posted messages 46 Status Member -
Hello,
I would like you to tell me which code I need to use to send a variable in a popup.
Let me explain, I am currently working on a dynamic website for the first time, featuring product sales. I have a page displaying all the selected product range with their photos.
I would like that when I click on the product photo, it opens the detailed sheet for that product, but in a popup.
Thank you in advance for your help.
I would like you to tell me which code I need to use to send a variable in a popup.
Let me explain, I am currently working on a dynamic website for the first time, featuring product sales. I have a page displaying all the selected product range with their photos.
I would like that when I click on the product photo, it opens the detailed sheet for that product, but in a popup.
Thank you in advance for your help.
Configuration: Windows XP Firefox 2.0.0.12
9 answers
Re,
Don't you see what's wrong? You're not passing any parameters to your pop-up (in the URL), so it's normal that you can't display anything.
To keep it simple, I recommend removing your link on the photo and simulating it instead (which means loading your image with an 'onclick' and adding an info in its style to change the cursor appearance when hovering over the image).
How do we do that? Instead of this:
You put this:
And you no longer need to redirect to a page that then opens a pop-up.
It's important to note:
style="cursor: pointer;"
Which allows you to change the cursor style on mouse hover, to inform the user that they can click on the image.
onclick="window.open(...
Which allows you to open a pop-up and load the page you want when the user clicks on the image.
'fiche_prod.php?numero=<?php echo $num_produit;?>'
Which allows you to call your page with the parameter you want (or parameters if there are multiple).
Attention: do not forget that you pass parameters via GET in your URL, so on your page 'fiche_prod.php' you will need to retrieve the variables via $_GET.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Don't you see what's wrong? You're not passing any parameters to your pop-up (in the URL), so it's normal that you can't display anything.
To keep it simple, I recommend removing your link on the photo and simulating it instead (which means loading your image with an 'onclick' and adding an info in its style to change the cursor appearance when hovering over the image).
How do we do that? Instead of this:
<a href="index.php?lien=popup&numero=<?php echo $num_produit;?>", target="_blank"><img src="<?php echo $photo_produit; ?>" width="90" height="100"> <a/>
You put this:
<a href="index.php?lien=popup&numero=<?php echo $num_produit;?>", target="_blank"><img src="<?php echo $photo_produit; ?>" width="90" height="100" style="cursor: pointer;" onclick="window.open('fiche_prod.php?numero=<?php echo $num_produit;?>','fiche','toolbar=no, location=no, directories=no, status=yes, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400, left=300, top=50')" > And you no longer need to redirect to a page that then opens a pop-up.
It's important to note:
style="cursor: pointer;"
Which allows you to change the cursor style on mouse hover, to inform the user that they can click on the image.
onclick="window.open(...
Which allows you to open a pop-up and load the page you want when the user clicks on the image.
'fiche_prod.php?numero=<?php echo $num_produit;?>'
Which allows you to call your page with the parameter you want (or parameters if there are multiple).
Attention: do not forget that you pass parameters via GET in your URL, so on your page 'fiche_prod.php' you will need to retrieve the variables via $_GET.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Hello,
Here is the JavaScript code to open a pop-up:
As you can see, you need to pass to this function the URL of the page you want to display in your pop-up, its name, and its properties (size, placement in the main window).
Just place this function in the chosen event (onclick) of your image and it should work.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Here is the JavaScript code to open a pop-up:
window.open(URL, NAME,"width=680,height=393,left=" + ((screen.width - 460)/2) + ",top=" + ((screen.height - 150)/2));
As you can see, you need to pass to this function the URL of the page you want to display in your pop-up, its name, and its properties (size, placement in the main window).
Just place this function in the chosen event (onclick) of your image and it should work.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Has your detail page already been coded? If so, it should take into account a parameter (the product ID to display, in order to select the correct information from your database to display on your page)
Conclusion: in the snippet of code I gave you, let's say your page is called index.php and it takes the parameter id, you will have to set the URL parameter as follows:
index.php?id=???
How to do this "dynamically"?
Well, when you are on your first page and you display a product thumbnail (in php), you just need to add a call to the javascript function I provided, giving it the properly formatted URL (with your id parameter that you should certainly have when you display your product thumbnail). If you don’t have it, figure out how to get it after your database query.
--
~ Don't forget the "Resolved" tag when your issue is... resolved :) ~
Conclusion: in the snippet of code I gave you, let's say your page is called index.php and it takes the parameter id, you will have to set the URL parameter as follows:
index.php?id=???
How to do this "dynamically"?
Well, when you are on your first page and you display a product thumbnail (in php), you just need to add a call to the javascript function I provided, giving it the properly formatted URL (with your id parameter that you should certainly have when you display your product thumbnail). If you don’t have it, figure out how to get it after your database query.
--
~ Don't forget the "Resolved" tag when your issue is... resolved :) ~
I think the best thing is for you to put your code here so that I can see what has been done / not done.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
- in my page with all my photos that automatically display in PHP:
<a href="index.php?lien=popup&numero=<?php echo $num_produit;?>" target="_blank"><img src="<?php echo $photo_produit; ?>" width="90" height="100"> </a>
- in my popup page:
<script language="JavaScript">
{
window.open('fiche_prod.php','fiche','toolbar=no, location=no, directories=no, status=yes, scrollbars=no, resizable=no, copyhistory=no, width=400, height=400, left=300, top=50');
}
</script>
* Thank you, enjoy it while it lasts :D *
In that case, show me the code for your product page.
Otherwise, try to display the value of the variable number that you retrieve by replacing:
With:
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
In that case, show me the code for your product page.
Otherwise, try to display the value of the variable number that you retrieve by replacing:
$num_produit = $_GET['numero'];
With:
if ( isset($_GET['numero'] ) ){ $num_produit = $_GET['numero']; echo "<BR>product number: ".$num_produit; } else { echo "<BR>product number not referenced"; exit; } --
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
What exactly is the error message?
Are you able to retrieve the number correctly from the popup?
Otherwise, you need to delete this code:
<a href="index.php?lien=popup&numero=<?php echo $num_produit;?>", target="_blank">
It’s not useful.
--
~ Don’t forget the "Resolved" tag when your issue is... resolved :) ~
Are you able to retrieve the number correctly from the popup?
Otherwise, you need to delete this code:
<a href="index.php?lien=popup&numero=<?php echo $num_produit;?>", target="_blank">
It’s not useful.
--
~ Don’t forget the "Resolved" tag when your issue is... resolved :) ~
I work directly on the internet because it doesn't work locally, why? That's still a good question lol, and I use Free as a free host. So the error message is from Free.
Otherwise, I've removed the part you pointed out, it looks better, at least I don't have a blank page and the popup appears directly above the products even if it's an error message inside, it looks better ;)
Otherwise, I've removed the part you pointed out, it looks better, at least I don't have a blank page and the popup appears directly above the products even if it's an error message inside, it looks better ;)
I don't really understand your message, do you want me to write what Free displays? Is that it?
If that's the case, it says:
Error 404 is an error code in the HTTP protocol. This code is returned by an HTTP server to indicate that the requested resource (usually a web page) does not exist. Some web browsers then display the message "404 File Not Found" (meaning "file not found" in English) to the user.
The first 4 indicates an error in the request, here a bad URL, coming from an outdated page or an error in web address entry by the visitor. The last 4 indicates the issue caused by this error: the resource is not found.
If that's the case, it says:
Error 404 is an error code in the HTTP protocol. This code is returned by an HTTP server to indicate that the requested resource (usually a web page) does not exist. Some web browsers then display the message "404 File Not Found" (meaning "file not found" in English) to the user.
The first 4 indicates an error in the request, here a bad URL, coming from an outdated page or an error in web address entry by the visitor. The last 4 indicates the issue caused by this error: the resource is not found.
Yes, that's exactly what I wanted to know.
404 -> file not found as you said.
This error appears in the popup, right?
If so, that means it actually can’t find the page 'fiche_prod.php'.
Is this page located in the same place as your page with all your products (same directory)?
If not, you need to correct the access path to the file 'fiche_prod.php' so that it can be found. You will need to include the access path to 'fiche_prod.php' from your script/page that displays all your products.
For example, if your Root directory looks like this:
Root
|- page1.php (page displaying all results)
|
|- detail
|- fiche_prod.php (product details page)
You will need to specify 'detail/fiche_prod.php?...' in the filename passed to the 'window.open(...)' instruction.
If, on the other hand, you have this type of structure:
Root
|- fiche_prod.php (product details page)
|
|- divers
|- page1.php (page displaying all results)
You will need to provide the following path: '../fiche_prod.php'
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
404 -> file not found as you said.
This error appears in the popup, right?
If so, that means it actually can’t find the page 'fiche_prod.php'.
Is this page located in the same place as your page with all your products (same directory)?
If not, you need to correct the access path to the file 'fiche_prod.php' so that it can be found. You will need to include the access path to 'fiche_prod.php' from your script/page that displays all your products.
For example, if your Root directory looks like this:
Root
|- page1.php (page displaying all results)
|
|- detail
|- fiche_prod.php (product details page)
You will need to specify 'detail/fiche_prod.php?...' in the filename passed to the 'window.open(...)' instruction.
If, on the other hand, you have this type of structure:
Root
|- fiche_prod.php (product details page)
|
|- divers
|- page1.php (page displaying all results)
You will need to provide the following path: '../fiche_prod.php'
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
And on the server, all the files have been updated correctly (through your FTP client you can see the files after refreshing)?
Strange, strange. It must be a silly mistake (as always ^^) but I'm having a hard time seeing it. They say the night brings advice, so see you tomorrow.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Strange, strange. It must be a silly mistake (as always ^^) but I'm having a hard time seeing it. They say the night brings advice, so see you tomorrow.
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
I hope you slept well and that your night was beneficial for you ;-) lol.
As for me, I couldn't stop thinking about it lol, it worries me not to succeed.
I set location=yes to see if it was looking for the right page, and yes, it says:
fiche_prod.php?numero=128
So this indicates that it should display the product sheet I clicked on, at least we know that the variable is being transmitted.
As for me, I couldn't stop thinking about it lol, it worries me not to succeed.
I set location=yes to see if it was looking for the right page, and yes, it says:
fiche_prod.php?numero=128
So this indicates that it should display the product sheet I clicked on, at least we know that the variable is being transmitted.
Yes, that's already something to check. Can you try not to pass the variable, that is to say to set the URL as only: fiche_prod.php
I have a feeling that it’s due to the parameter passing that the page is not found. If that's the case, it's a "configuration issue" (I think) with the free server. You should check with the "advisory" service (if there is one) of free and ask them the question (if that’s the case).
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
I have a feeling that it’s due to the parameter passing that the page is not found. If that's the case, it's a "configuration issue" (I think) with the free server. You should check with the "advisory" service (if there is one) of free and ask them the question (if that’s the case).
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Ok, that's good. I don't understand why a 404 error was displayed in this case. Resource not found, it referred to the missing connection to the database, but their message is not very explicit ^^
Good if it works.
Good luck for the rest. ++
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
Good if it works.
Good luck for the rest. ++
--
~ Don't forget the "Resolved" tag when your problem is... resolved :) ~
And in my product sheet, I had already entered at the very beginning of my page:
$num_produit = $_GET['numero'];
Otherwise, a little compliment, I think you explain really well ;-)