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
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Writing comments on <p></P> or paragraph 2 19
Html Newline 7 21
Html input text color the frame line 2 21
javascript - insert into js doc help 2 25
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
This article discusses how to create an extensible mechanism for linked drop downs.
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 how to count occurrences of each item in an array.

837 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