Jump to content

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

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>

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...