Solved

Storing The Date into a Var From a Popup Window Date Picker

Posted on 2012-03-22
4
320 Views
Last Modified: 2012-03-22
Hello,

I really need your help with one.

How can I use the following code below to save the date from my popup window datepicker back into a var and relay it back onto its parent page?

I can't seem to figure this out:

<html>
<head>
<script>
function open_cal() {
  var str_html = ""
      +  "<!DOCTYPE html>\n"
      +  "<html lang=\"en\">\n"
      +  "<head>\n"
      +  "<meta charset=\"utf-8\">\n"
      +  "<title>CALENDAR</title>\n"
      +  "<link href=\"jq/jquery-ui.css\" rel=\"stylesheet\" type=\"text/css\">\n"
      +  "<script src=\"jq/jquery.min.js\" type=\"text/javascript\"></" + "script>\n" 
      +  "<script src=\"jq/jquery-ui.min.js\" type=\"text/javascript\"></" + "script>\n"
      +  "<script src=\"jq/datepicker.js\" type=\"text/javascript\"></" + "script>\n"
      +  "</head>\n"
      +  "<body>\n"
      +  "<div id=\"text\" style=\"font: bold 10pt Tahoma\">Enter Approval Date:</div>\n"
      +  "<div id=\"datepicker\"></div>\n"
      +  "</body>\n"
      +  "</html>"
          
var j = window.open("","CALENDAR","width=200,height=250,status=no,resizable=yes,top=200,left=200")
  j.opener = self;
  j.document.write(str_html);
}
</script>  
</head>
<body>
<input onclick="open_cal()" type="button" value="Open" name="B1">
</body>
</html>

Open in new window


DatePicker.js:
$(function() {
  $( "#datepicker" ).datepicker({ 
    dateFormat: 'dd/mm/yy',
    onSelect: function(dateText, inst) { 
      alert(dateText)
      window.close()
    } 
  })
});

Open in new window


Any help with this is greatly and mostly appreciated.

Thanks in advance,

Cheers,

J
0
Comment
Question by:Buggs2012
[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
  • 3
4 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37752359
1) I formatted your code to be more readable
2) you forgot to do
j.document.close();
after the .write(...)
3) Why do you set the opener to self?????
4) If you don't you can just do
opener.dateValue = dateText
or
opener.someFunction(datetext);

but I also suggest you format like this - much more readable
<html>
<head>
<script>
function open_cal() {
  var str_html = ''
      +  '<!DOCTYPE html>\n'
      +  '<html lang="en">\n'
      +  '<head>\n'
      +  '<meta charset="utf-8">\n'
      +  '<title>CALENDAR</title>\n'
      +  '<link href="jq/jquery-ui.css" rel="stylesheet" type="text/css">\n'
      +  '<script src="jq/jquery.min.js" type="text/javascript"><\/script>\n' 
      +  '<script src="jq/jquery-ui.min.js" type="text/javascript"><\/script>\n'
      +  '<script src="jq/datepicker.js" type="text/javascript"><\/script>\n'
      +  '</head>\n'
      +  '<body>\n'
      +  '<div id="text" style="font: bold 10pt Tahoma">Enter Approval Date:</div>\n'
      +  '<div id="datepicker"></div>\n'
      +  '</body>\n'
      +  '</html>'
          
var j = window.open('','CALENDAR','width=200,height=250,status=no,resizable=yes,top=200,left=200')
//  j.opener = self; // this cannot be what you want!!!
  j.document.write(str_html);
  j.document.close();
}
</script>  
</head>
<body>
<input onclick='open_cal()' type='button' value='Open' name='B1'>
</body>
</html>

Open in new window

0
 

Author Comment

by:Buggs2012
ID: 37752860
Hi mplungjan,

I tried what you have posted,

and for the life of me, still cannot get this to work.

'opener.dateValue is null or not an object'

<html>
<head>
<script>


function test() {

alert(opener.dateValue)

}



function open_cal() {
  var str_html = ''
      +  '<!DOCTYPE html>\n'
      +  '<html lang="en">\n'
      +  '<head>\n'
      +  '<meta charset="utf-8">\n'
      +  '<title>CALENDAR</title>\n'
      +  '<link href="jq/jquery-ui.css" rel="stylesheet" type="text/css">\n'
      +  '<script src="jq/jquery.min.js" type="text/javascript"><\/script>\n' 
      +  '<script src="jq/jquery-ui.min.js" type="text/javascript"><\/script>\n'
      +  '<script src="jq/datepicker.js" type="text/javascript"><\/script>\n'
      +  '</head>\n'
      +  '<body>\n'
      +  '<div id="text" style="font: bold 10pt Tahoma">Enter Approval Date:</div>\n'
      +  '<div id="datepicker"></div>\n'
      +  '</body>\n'
      +  '</html>'
          
var j = window.open('','CALENDAR','width=200,height=250,status=no,resizable=yes,top=200,left=200')
  j.document.write(str_html);
  j.document.close();
}
</script>  
</head>
<body>
<input onclick='open_cal()' type='button' value='Open' name='B1'>

<input onclick='test()' type='button' value='GetTheDate' name='B2'>

</body>

</html>

Open in new window


Datepicker.js:
$(function() {
	
		$( "#datepicker" ).datepicker({ 
		
		dateFormat: 'dd/mm/yy',
		
		onSelect: function(dateText, inst) { 
		
		alert(dateText)
		
		opener.dateValue = dateText
		
		window.close()
		
		} 
		
		})	
		
});	

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37753011
Parent window

var dateValue="";

function test() {
  alert(dateValue)
}

Open in new window


----

Child window:

$(function() {
  $( "#datepicker" ).datepicker({ 
    dateFormat: 'dd/mm/yy',
    onSelect: function(dateText, inst) { 
      opener.dateValue=dateText;
      opener.test();
      window.close()
    } 
  })
});

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37753020
or better:

Parent window

var dateValue="";

function test(val) {
  dateValue=val;
  alert(dateValue);
}

Open in new window


----

Child window:

$(function() {
  $( "#datepicker" ).datepicker({ 
    dateFormat: 'dd/mm/yy',
    onSelect: function(dateText, inst) { 
      opener.test(dateText);
      window.close()
    } 
  })
});

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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