Link to home
Start Free TrialLog in
Avatar of TLN_CANADA
TLN_CANADAFlag for Afghanistan

asked on

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
Avatar of guru_sami
guru_sami
Flag of United States of America image

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

Avatar of TLN_CANADA

ASKER

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
I want both of the links to open the same popup page, just with the different value.
So by pop-up you mean a new page?
Yes, I want it to pop-up in a new window (page)
Avatar of Marco Gasi
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">
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.
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?
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
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?
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

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

ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much! It's working perfectly now!