Solved

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

Posted on 2012-03-22
4
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 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

10 Experts available now in Live!

Get 1:1 Help Now