views:

593

answers:

2

I am developing my website using jQuery. For the Private Messaging feature, what I had right now is showing a ModalBox(dialog box). So, whenever user wanna check message, they will be displayed with a dialog box with the inbox shown. Now, inside that ModalBox, I have a "Compose" section where users can send message. My question is, when user submits the form, how we could retrieve those inputs without having to actually submit it? Because, I have tried it..., that when I do the "submit()", it closed the ModalBox.

Any help would be appreciated.

A: 

Use Ajax to make the request.

Josh Stodola
I did use Ajax for the request. Since I have an id for the input, I use the selector and call the function val() (in hope of getting the value). But, it says "undefined"
Just a note, I don't think I mentioned this. This form are not prepared on the php or html. It is created "on the fly" using Ajax.
Then you have the wrong id.
Josh Stodola
A: 

Since you're using jQuery, see here

In case you're not familiar with AJAX, basically it allows you to send a request to the server (in this case, your submitted data), process the data on the server, and then receive any return back from your request, all without reloading the entire page.

This should alleviate the issue of the modal box closing (the page reloading upon submit, really.)

[edit]

See this article from here at StackOverflow on using the live event handler. This should take care of the issue of not getting the value from newly created DOM elements.

[/edit]

idrumgood
Hey, I do use a lot of Ajax in developing my current website. I am still learning jQuery. Just a note, I don't think I mentioned this. This form are not prepared on the php or html. It is created "on the fly" using Ajax.
Take a look at the edited answer. It has a link on handling on-the-fly created DOM elements. This should solve your problem of the 'undefined' val() hopefully.
idrumgood