Skip to content
Advertisement

Get data from regular form inputs alongwith contents in div

I have a little email system on my wordpress site wherein people submit php generated content to me via email. Basically the content is generated within a div and then via a little javascript the div-content is mailed to me. I am skipping the part how it is generated in order to keep the focus on the main issue. Here is an illustration.

JavaScript

Please note the first div-id”aricle” block, it contains the main content, which I have been getting fine Now notice the second div-id “visitor” block right below the first block. I have not been able to get the input of that one. I would prefer to get it as a regular form text input.

I think the reason I am not able to get the input is because I am not having any <form></form> tag. But then the main part is working, so I just need it work along-with it somehow. I leave it upto you guys to suggest me solution or a best way to get both the data. I am familiar with a little php but javascript, not at all.

Here is the content of the processForm.php. All these have been put together by learning what I could from several articles on the web. Many thanks in advance.

JavaScript

Advertisement

Answer

I am just sharing the code below to get the value of required textbox in the provided div id = “visitor”, I hope it helps to get your desired results:

JavaScript

I have replaced $('#visitor').html() to $('#name').val() in your script, as the below is the explanation:

  • $('#visitor').html() = gives the inner HTML content of that div of id = “visitor” which is a text box and I am sure that you are interested in the value entered by any user into that text box.

  • $('#name').val() = gives you the value of text box whose id = “name”

I hope the above will help you to get desired results with explanation.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement