?
Solved

Opening Popup with values sent in javascript

Posted on 2013-01-24
16
Medium Priority
?
543 Views
Last Modified: 2013-01-25
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
Comment
Question by:TLN_CANADA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 2
16 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38816951
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
 

Author Comment

by:TLN_CANADA
ID: 38816961
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
 

Author Comment

by:TLN_CANADA
ID: 38816964
I want both of the links to open the same popup page, just with the different value.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 41

Expert Comment

by:guru_sami
ID: 38817012
So by pop-up you mean a new page?
0
 

Author Comment

by:TLN_CANADA
ID: 38817017
Yes, I want it to pop-up in a new window (page)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38817586
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
 

Author Comment

by:TLN_CANADA
ID: 38817704
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38817717
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
 

Author Comment

by:TLN_CANADA
ID: 38817760
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38817770
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
 

Author Comment

by:TLN_CANADA
ID: 38817784
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38817800
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
 

Author Comment

by:TLN_CANADA
ID: 38817816
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
 

Author Comment

by:TLN_CANADA
ID: 38817846
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
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 38817889
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
 

Author Comment

by:TLN_CANADA
ID: 38817901
Thank you very much! It's working perfectly now!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question