Nontenda
Nontenda

Reputation: 185

Get HTML Source with Values attributes set for Input

I'm using jQuery to send an HTML document which contains a form to a C# WebService. The webService parse it and try to read "value" attribute of all inputs in the form.

The problem is that I send the HTML doc to the webservice with

var HTMLDoc = document.getElementById('foo').innerHTML;

And it does not returns the input with value attribute. For example, I got a :

<input type="text" id="foo" />

And I want the JavaScript to get :

<input type="text" id="foo" value="bar" />

when I do something like

document.getElementById('foo').innerHTML;

Is this possible ? Any idea ?

Upvotes: 0

Views: 297

Answers (2)

user1697238
user1697238

Reputation:

you can try it

HTML

<input type="text" name="foo" id="foo" />

in Jquery :

var foo = $("#foo").val();
alert("Jquery foo value : " + foo);

in JavaScript :

var foo = document.foo.value;
alert("JavaScript foo value : " + foo);

Upvotes: 1

Shuping
Shuping

Reputation: 5458

Try

document.getElementById('foo').outerHTML

Upvotes: 0

Related Questions