1

HTML Part:-

<form id="inquiryform" method="" />
    <h2>INQUIRY FORM</h2>
    <div class="margin5">
        <div class="floatleft width100"><span class="borderbottom">Party Name</span> </div>
        <div class="floatleft"><input type="text" name="PartyName" size="60"/></div>
        <div class="clear"></div>
    </div>
</form>
<div> <input type="button" id="submitform" value="Send Mail"/></div>

Jquery :-

$(document).ready(function () {
    $('#submitform').click(function(){
        var data = 'message='+$('#inquiryform').html();
        alert(data);
    });
});

When I click on my send mail button then it will OK html part which I want to get but when I entered something in textbox then data variable always be empty. I want to like that whatever I write in text-box that must be a part of the data variable.

Anish Gupta
  • 2,218
  • 2
  • 23
  • 37
Maulik patel
  • 1,551
  • 8
  • 22
  • 44

3 Answers3

1

The text entered in the <input> doesn't show in the .html() result because it doesn't change the DOM. It just affects the value property (not the attribute) of the element.

If you want to retrieve its value you should use $("[name=PartyName]").val().

MaxArt
  • 22,200
  • 10
  • 82
  • 81
1

Add this lines before 'var data=...' line:

$('#inquiryform :text').attr('value',function(){
    return $(this).val();
});

This will add 'value' attribute on all input[type="text"] tags.

DEMO

Engineer
  • 47,849
  • 12
  • 88
  • 91
0

If you want all the data of every element of the form (not the html, just data) use serialize()

nax
  • 1,184
  • 1
  • 8
  • 19