Results 1 to 2 of 2

Thread: Javascript post back

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript post back

    I have two html pages
    results.html
    choose.html

    results.html pop up a new window (choose.html) using Javascript.
    and there are radio buttons on choose.html

    I want when I choose option1, its should return my option back to results.html page.

    Plz any ideas

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the following

    1. save the below mentioned code as result.htm (you can use any name but for this file but make sure that the second file should be choose.htm. Save these file in some other locations where there is no file for name conflict).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    var result = null;
    function openWindow()
    {
    	var win = window.open("choose.htm","","height=400,width:900");
    	win.focus;
    }
    
    function showResult()
    {
    	if(result == null)
    	{
    		alert('Null value; quitting....');
    		return;
    	}
    	
    	alert('The value stored in result variable is : '+ result);
    	return;
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" name="open" value="Open New Window"  onclick="javascript: openWindow();" />
    <input type="button" name="show" value="Show Result"  onclick="javascript: showResult();" />
    
    </form>
    </body>
    </html>
    2. Save the below mentioned code in the same location where the file is stored. Save it as choose.htm

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript">
    function copyValueToParentWindow(radioButtonValue)
    {
    	window.opener.result = radioButtonValue;
    	return;
    }
    </script>
    </head>
    
    <body>
    <form name="f1">
    Are you interested in computers? 
    <input type="radio" name="interest" value="Yes" onclick="javascript: copyValueToParentWindow(this.value);"/> Yes
    <input type="radio" name="interest" value="No" onclick="javascript: copyValueToParentWindow(this.value);" /> No
    </form>
    </body>
    </html>
    You can pass values from a child window to its parent window using window.opener

    Now open the first file in browser
    1. click on the first button which will open a new window in which the second file will be loaded.

    2. click any one of the radio button available in the new window and then go back to the parent window (first window) and click the second button (Show Result).

    3. You will be able to view the value of the radio button you've clicked on the new window

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •