Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP Javascript
hello experts,
need your guidance its urgent!
code for ASP textbox and button:
<INPUT id="txtSchX" NAME="txtSchX" size="72">
<Input type="button"  value="..." onmouseover="window.status ='Show School Name';return true;" onmouseout="window.status='';return true;" Onclick="javascript:show_School();">
 
and code in javascript:
function show_School()
{
    var myWindow;
    myWindow = window.open("","SchoolName","width=265,height=210,status=no,resizable=no,top=200,left=600");
    myWindow.document.write("<html>");
    myWindow.document.write("<head><title>School Name</title>");
    myWindow.document.write("</head>");
    myWindow.document.write("<body>" );
    myWindow.document.write("<table>");
    myWindow.document.write("<tr><td><a href='#' onClick='wondow.close();'></a>Manish Kumar</td></tr>");
}
it works fine when i click on button it open a pop up with a link (Manish Kumar),
and when i click on the link it close this popup..
 
Experts, actually i want that if i click on the link it will print my name into the textbox.
please guide me how can i do so????
urgent needed
Posted 22-Apr-13 22:01pm
Edited 22-Apr-13 22:13pm
v3
Comments
Prasad Khandekar at 23-Apr-13 3:11am
   
You cannot return a value from window.open. However you will be able to call a JavaScript function from the parent window. Simply use code similar to one shown below. Here I am assuming that the parent window's javascript has a function named doSomething.
 
var hWin = Window.Opener;
if (hWin)
hWin.doSomething(param1, param2, ...);
 
Please note the above mentioned code needs to be in JavaScript referenced by the popup window.
 
Regards,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Here is a small html to demonstrate how it can be done.
<html>
<head>
<title>JS Popup</title>
<script type="text/javascript">
function show_School() {
    var myWindow;
    myWindow = window.open("", "SchoolName", "width=265,height=210,status=no,resizable=no,top=200,left=600");
    myWindow.document.write("<html>");
    myWindow.document.write("<head><title>School Name</title>");
    myWindow.document.write("<" + "script" + ">");
    myWindow.document.write("function sendName(arg) {var hWin=window.opener;if(hWin)hWin.printName(arg);window.close();}");
    myWindow.document.write("<" + "/script" + ">");
    myWindow.document.write("</head>");
    myWindow.document.write("<body>" );
    myWindow.document.write("<table>");
    myWindow.document.write("<tr><td><a href=\"#\" onClick=\"sendName('Manish Kumar');\">Manish Kumar</a></td></tr>");
}
 
function printName(args) {
    var txt = document.getElementById('txtSchX');
	txt.value = args;
}
</script>
</head>
<form id="frmMain" name="frmMain">
    <input type="text" id="txtSchX" NAME="txtSchX" size="72">
    <Input type="button"  value="..." Onclick="show_School();">
</form>
</html>
Regards,
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

<script language="javascript">
// Manish's Code for get School Name on 24-Apr-2013 Starts Here

var vDay = ["","CARMEL JUNIOR COLLEGE, SONARI","DAV PUBLIC SCHOOL, BISTUPUR", "DAV PUBLIC SCHOOL, NIT","DBMS ENGLISH SCHOOL, KADMA",
 "HILL TOP SCHOOL, TELCO","JAMSHEDPUR PUBLIC SCHOOL, BARIDIH","KERALA PUBLIC SCHOOL, KADMA","KERALA SAMAJAM MODEL SCHOOL, SAKCHI",
 "LITTLE FLOWER SCHOOL, TELCO","LOYALA SCHOOL, JAMSHEDPUR","MOTILAL NEHRU PUBLIC SCHOOL, SAKCHI","MRS K M P M INTER COLLEGE, JAMSHEDPUR",
 "NARBHERAM HANSRAJ ENGLISH SCHOOL, BISTUPUR","RAJENDRA VIDYALAYA, SAKCHI","SACRED HEART CONVENT SCHOOL, JAMSHEDPUR",
 "ST MARYS ENGLISH HIGH SCHOOL, BISTUPUR","VIDYA BHARTI CHINMAYA VIDYALAYA, TELCO","VIVEK VIDYALAYA, CHHOTA GOVINDPUR"];
 
var fontface = "Verdana";
var fontsize = 2;
var ggWinCal;
isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
 
function SchoolName(p_item, p_WinCal) {
    //alert(p_item);
    if (p_WinCal == null)
        this.gWinCal = ggWinCal;
    else
        this.gWinCal = p_WinCal;
 
    this.gReturnItem = p_item;
}
 
SchoolName.prototype.getMonthlySchoolNameCode = function() {
    var vCode = "";
    var vHeader_Code = "";
    var vData_Code = "";
    vData_Code = this.cal_data();
    vCode = vCode + vHeader_Code + vData_Code;
    vCode = vCode + "</TABLE>";
    return vCode;
}
 
SchoolName.prototype.show = function() {
    var vCode = "";
 
    this.gWinCal.document.open();
    this.wwrite("<html>");
    this.wwrite("<head><title>School Name</title>");
    this.wwrite("</head>");
 
    this.wwrite("<body>");
    this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
    this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR='white'><TR><TD ALIGN=center>");
    vCode = this.getMonthlySchoolNameCode();
    this.wwrite(vCode);
    this.wwrite("</font></body></html>");
    this.gWinCal.document.close();
}
 
SchoolName.prototype.wwrite = function(wtext) {
    this.gWinCal.document.writeln(wtext);
}
 
SchoolName.prototype.wwriteA = function(wtext) {
    this.gWinCal.document.write(wtext);
}
SchoolName.prototype.cal_data = function() {
    var vCode = "";
    for (i=1; i<=vDay.length-1; i++)
    {
    vCode = vCode + "<TR>";
 
    for (j=0; j<1; j++) {
        vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "'>" +
            "<A style='COLOR: blue; ' HREF='#' " + "onClick=\"self.opener.document." + this.gReturnItem + ".value='" + vDay[i] + "';window.close();\">"+i+". " + vDay[i] + "</A>" + "</FONT></TD>";
 
    }
    vCode = vCode + "</TR>";}
 
    return vCode;
}
 
function SchBuild(p_item) {
    var p_WinCal = ggWinCal;
    gCal = new SchoolName(p_item, p_WinCal);
 
    gCal.gBGColor="white";
    gCal.gLinkColor="black";
    gCal.gTextColor="black";
    gCal.gHeaderColor="darkgreen";
    gCal.show();
}
 
function show_SchName()
{
    p_item = arguments[0];
 
    vWinCal = window.open("", "SchoolName","width=395,height=335,status=no,resizable=no,top=220,left=380");
    vWinCal.opener = self;
    ggWinCal = vWinCal;
 
    SchBuild(p_item);
}
 
// Manish's Code for get School Name on 24-Apr-2013 Ends Here
</Script>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 319
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 CPallini 205
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100