Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Opening Popup with values sent in javascript

Hi all,

I have a page like this setup with a menu where users can select different exercise times. If the user clicks the first link I want it to send a value of 40, the second link a value of 30 when it opens a pop up page.  

<div class="col_1 firstcolumn">
                    <a href="#" >Standard  </br>(40 Minutes) </br> (5 minute intervals)</a>
                    </div>
                    
                    <div class="col_1">
                    <a href="#" >30 Min </br>(30 Minutes) </br> (5 minute intervals)</a>
                    </div>

Open in new window




The initial value of the pop up (child) page is set here in the pop page code:

	<input type = "text" id = "Minutes" value = "40" readonly="readonly">

Open in new window


Can someone show me how to create a pop up page that sends the value in this way?

Thanks very much,

D
0
TLN_CANADA
Asked:
TLN_CANADA
  • 9
  • 5
  • 2
1 Solution
 
guru_samiCommented:
How are you  handling the click on the links?
One way is here that uses link's title and jquery:

   
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script  type="text/javascript">
        $(function () {
            $(".col_1 a").click(function () {
               $("#Minutes").val($(this).attr("title"));
            });
        });
    </script>

<div class="col_1 firstcolumn">
                    <a href="#" title="40" >Standard  <br/>(40 Minutes) <br/> (5 minute intervals)</a>
                    </div>
                    
         <div class="col_1">
                    <a href="#" title="30" >30 Min <br/>(30 Minutes) <br/> (5 minute intervals)</a>
         </div>
        <input type = "text" id = "Minutes" value = "40" readonly="readonly">

Open in new window

0
 
TLN_CANADAAuthor Commented:
Thanks, I have not setup the popup yet. How should I do it so it passes the values like this? The popup page is called mednow2.htm
0
 
TLN_CANADAAuthor Commented:
I want both of the links to open the same popup page, just with the different value.
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
guru_samiCommented:
So by pop-up you mean a new page?
0
 
TLN_CANADAAuthor Commented:
Yes, I want it to pop-up in a new window (page)
0
 
Marco GasiFreelancerCommented:
Try this:

<div class="col_1 firstcolumn">
    <a href="popup.php?min=40" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</</div>
                   
<div class="col_1">
    <a href="popup.php?min=30" target="_blank">30 Min </br>(30 Minutes) </br> (5 minute intervals)</a>
</div>

In the popup:

<?php
if (isset($_GET['min']) $$ is_int($_GET['min'])){
  $min = $_GET['min'];
}else{
  $min = 40;
}
?>
<input type = "text" id = "Minutes" value = "<?php echo $min; ?>" readonly="readonly">
0
 
TLN_CANADAAuthor Commented:
Thank you so much Marco! A couple of small changes this to if it's okay. When sending the values I would like to send the minute intervals also so should it look like this:

    <a href="popup.php?min=40int=5" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</</div>

Open in new window


Also for the child page if this page is not being opened by the parent page I would like this field

<input type = "text" id = "Minutes" value = "<?php echo $min; ?>" readonly="readonly">

Open in new window


to have a default value of 25.
0
 
Marco GasiFreelancerCommented:
For the first problem do this:

    <a href="popup.php?min=40&int=5" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</</div>

Open in new window


Add an ampersand to separate parameters;

fFor the second question, I'm not sure to understand what you want: can you be more clear, please?
0
 
TLN_CANADAAuthor Commented:
Oh it's okay, I see you have set the default value already :)

It's giving an error on line 2 though on the child page, here's what I have at the start

<?php
if (isset($_GET['min']) $$ is_int($_GET['min'])){
  $min = $_GET['min'];
}else{
  $min = 40;
}
if (isset($_GET['int']) $$ is_int($_GET['int'])){
  $min = $_GET['int'];
}else{
  $min = 05;
}
?>

Open in new window


and the error:

Parse error: syntax error, unexpected '$' in /home/clear555/public_html/mednowphp.php on line 2
0
 
Marco GasiFreelancerCommented:
Ooops! Replace the two $$ with two ampersand &&:
<?php
if (isset($_GET['min']) && is_int($_GET['min'])){
  $min = $_GET['min'];
}else{
  $min = 40;
}
if (isset($_GET['int']) && is_int($_GET['int'])){
  $min = $_GET['int'];
}else{
  $min = 05;
}
?>

Open in new window


Sorry, what time is it for you?
0
 
TLN_CANADAAuthor Commented:
It's late here, after 12 at night :) It isn't giving an error now but when I open the child page it is not displaying the initial values correctly. Here is what I have, am I doing something wrong here:

Top of the page:

<?php
if (isset($_GET['min']) && is_int($_GET['min'])){
  $min = $_GET['min'];
}else{
  $min = 40;
}
if (isset($_GET['int']) && is_int($_GET['int'])){
  $min = $_GET['int'];
}else{
  $min = 05;
}
?>

Open in new window


	<input type = "text" id = "Minutes" value = "<?php echo $min; ?>" readonly="readonly">
    <input type = "text" id = "Seconds" value = "00" readonly="readonly">
	<input type = "text" id = "Interval" value = "<?php echo $int; ?>" readonly="readonly">

Open in new window

0
 
Marco GasiFreelancerCommented:
In the first block of code you're assigning values always to $min variable: first you assing it the value of $_GET['min'] and then you assign it the value of $_GET['int']:

<?php
if (isset($_GET['min']) && is_int($_GET['min'])){
  $min = $_GET['min'];
}else{
  $min = 40;
}
if (isset($_GET['int']) && is_int($_GET['int'])){
  $int = $_GET['int'];
}else{
  $int = 05;
}
?>

Open in new window


Now it should work.
0
 
TLN_CANADAAuthor Commented:
Yes, it does display correctly now when I load the page but when I try to pass the values from the parent page to the child page the values do not pass at all and it just displays the default ones. Here is how it looks on the parent page:

<div class="col_1 firstcolumn">
                    <a href="http://www.clear.com/mednowphp.php?min=22&int=65" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</</div>
                    </div>

In the url on the child page it looks correct:

http://www.clear.com/mednowphp.php?min=22&int=65

Any ideas what's going on?
0
 
TLN_CANADAAuthor Commented:
Would it have another to do with the form on the child page. I've tried both the post and get on it but neither work.. .

<form id="form2" name="form2" method="post" action="">	
	<input type = "text" id = "Minutes" value = "<?php echo $min; ?>" readonly="readonly">
    <input type = "text" id = "Seconds" value = "00" readonly="readonly">
	<input type = "text" id = "Interval" value = "<?php echo $int; ?>" readonly="readonly">
	</form>
	

Open in new window

0
 
Marco GasiFreelancerCommented:
First, this code is wrong:

<div class="col_1 firstcolumn">
                    <a href="http://www.clear.com/mednowphp.php?min=22&int=65" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</</div>
                    </div>

it should be:

<div class="col_1 firstcolumn">
                    <a href="http://www.clear.com/mednowphp.php?min=22&int=65" target="_blank">Standard  </br>(40 Minutes) </br> (5 minute intervals)</a>
                    </div>

But the error depends on the value type check I inserted for security reasons: parameters in url string are string so is_int check fails. I've modified the code to make it work but being still secure, forcing the $_GET['min'] and $_Get['int'] parameters to be integer:

<?php
if (isset($_GET['min'])){
  $min = (integer)$_GET['min'];
}else{
  $min = 40;
}
if (isset($_GET['int'])){
  $int = (integer)$_GET['int'];
}else{
  $int = 05;
}
?>

Open in new window


Cheers (I'll take a look to the cron job too as soon as possible)
0
 
TLN_CANADAAuthor Commented:
Thank you very much! It's working perfectly now!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 9
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now