Solved

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

810 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