I used JavaScript to open a new window(child) when user clicks on button from parent window.
On new window(child), I have textbox and button, I need to get the value of the textbox and pass to parent window when user clicks on button, while closing the child window, I need the updated value inserted into parent window (without refreshing parent window) so I can display my value to some hidden field/ label of the parent window , how can I do that?
1- parent window has button, clicked child window opened 2- child window has textbox and button, when button clicked, child will do a post to server to update database, then pass the value of textbox to parent window without refreshing parent window, and close child window.
How can I do that? Is it can be done with simple JavaScript? If I do it using jquery, will I have more benefit? Could anyone advice how can I do it?
To create a popup, add the data-role="popup" attribute to a div with the popup contents. Then create a link with the href set to the id of the popup div, and add the attribute data-rel="popup" to tell the framework to open the popup when the link is tapped. A popup div has to be nested inside the same page as the link.
Note. A prompt box is used if you want the user to input a value. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed.
$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.
You can then use CSS rules to hide the popup by default and show it when it is :target ed, (or the other way around), and add buttons to open and close the popup via navigating to the relevant fragment.
I would suggest using the jQuery dialog widget instead of an actual, new window. This will make it easier to access the new value as it's in the same window's DOM. Just have the callback from the button that closes the window extract the value from the DOM element contained in the dialog and copy it to the target DOM element on the form.
$('#popupDialog').dialog({
modal: true,
autoOpen: false,
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'Accept': function() {
$('#mainForm input#target').val( $(this).find('#widgetName').val() );
$(this).dialog('close');
}
});
$('#popupButton').click( function() {
$('#popuDialog').dialog('open');
});
<div id="popupDialog" title="Input a new widget name">
<p>
<label for="widgetName">Please input a new widget name:</label>
<input type="text" id="widgetName" />
</p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With