Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery can do this? popup window for value

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?

like image 575
i need help Avatar asked Jul 05 '09 16:07

i need help


People also ask

How to create jQuery popup window?

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.

Which pop window is used to take value?

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.

What is $$ in jQuery?

$ 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.

How to add close button in popup in html?

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.


1 Answers

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>
like image 157
tvanfosson Avatar answered Oct 31 '22 17:10

tvanfosson