Solved

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

Posted on 2012-03-22
4
316 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

862 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now