Jump to content

Adding a value into parent window textbox value from child window in a dynamic way


najubudeen
 Share

Recommended Posts

hi, i have a pop up window i have written my whole codes below. i have dynamic div tags structure. if i clicked any an char tag link in a parent window, it opens a child window.it has two form fields like text box and button. if a user add text into text box of child window and click button, the value should be added into parent window textbox value near to already clicked an char link. how do i do that.

 

 

this is my JavaScript in parent window parent.html

function opn_wind_par_fing(clicked_id){ window.open("child3-find.html","Open new window","width=550,height=170,left=150,top=200,toolbar=1,status=1,"); window.buttonid = clicked_id;}

this is my HTML in parent window parent.html

<form method=post action='' ><div id="main"><a href="javascript:void(0);" id="my_id-0" name="sho-name" onclick="opn_wind_par_fing(this.id);">click</a><div><input type="textbox" id="my-input-0" class="input-class" value=""/></div></div><div id="main"><a href="javascript:void(0);" id="my_id-1" onclick="opn_wind_par_fing(this.id);">click</a><div><input type="textbox" id="my-input-1" class="input-class"value="" /></div></div><div id="main"><a href="javascript:void(0);" id="my_id-2" onclick="opn_wind_par_fing(this.id);">click</a><div><input type="textbox" id="my-input-2" class="input-class" value=""/></div></div></form>

it is my JavaScript in child window child3-find.html

$(document).ready(function(){  $('#my_btn').click(function(e){  e.preventDefault();  var input_value = $("#txt_field").val();  var clicked_elem_id = window.opener.buttonid; $('#'+clicked_elem_id).next().$(window.opener.document).find('.input-class').input_value; window.close(); });});

my HTML in child window child3-find.html

<form method="post" action="">Your name<input type="text" id="txt_field" size=12 value="test"><input type="button" id="my_btn" value="Send"></form>
Link to comment
Share on other sites

You should save the window object and then you can define properties and methods on it, e.g.:

var win = window.open(...);win.buttonid = clicked_id;win.do_update = function() {  alert('Updating for ' + clicked_id + ' on the parent window from the child.');}
Now, inside the child window, you can execute window.do_update() to run that function that you defined from the parent, and it can use variables like clicked_id to figure out what needs to get updated on that page.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...