Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: Get original input value

Tags:

Is it possible to get the initial value of a form input field?

For example:

<form action="" id="formId">     <input type="text" name="one" value="one" id="one" /> </form>  $("#one").attr("value");   //would output "one" $("#one").val();           //would output "one" $("#one").get(0).value;    //would output "one" 

However, if the user then changed the content of the #one input field to two, the html would still look the same (with one as the value) but the JQuery calls above would return two.

JSFiddle to play with: http://jsfiddle.net/WRKHk/

I think that this must still be possible to get the orginal value, since we are able to call document.forms["formId"].reset() to reset the form to its original state.

like image 926
My Head Hurts Avatar asked Dec 13 '11 14:12

My Head Hurts


People also ask

How can get input tag value in jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

What does VAL () do in jQuery?

val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined .

How do I find a textbox ID?

Solution 1. You can set a common class for your textbox inside grid and then using class you can get text box id and it's value.


1 Answers

Try this:

$("#one")[0].defaultValue; 
like image 147
graphicdivine Avatar answered Oct 05 '22 13:10

graphicdivine