JQuery: Get Original Input Value January 05, 2023 Post a Comment Is it possible to get the initial value of a form input field? For example: Solution 1: Try this: $("#one")[0].defaultValue; Copy Solution 2: The DOM element has the attribute "value" which you can access by: element.getAttribute('value'); Copy ... which may be different from the element's property value. Demo Note that you may call .setAttribute('value', 'new value') which will actually affect any form.reset() that is called after. Solution 3: Input element got property called defaultValue that is storing the original value. To reach it via jQuery, just use .prop():Baca JugaBootstrap : Uncaught Typeerror: $(...).datetimepicker Is Not A FunctionSite Behaves Differently When Developer Tools Are Open Ie11When Is Triggered Ajax Success? var value = $(this).prop("defaultValue"); Copy Updated jsFiddle - after changing to "two", the above will return "one". Solution 4: The HTML does change. Just that the browser's default view source tool always shows you the original source fetched from server. If you use something like Firebug, you'll be able to see the dynamic changes in HTML. One way of getting the initial value is by storing it in an additional attribute in addition to 'value'. For example, if you serve out your HTML like: <input type="text" name="one" value="one" origvalue="one" id="one" /> Copy You can always get back the original value by calling: $("#one").attr("origvalue"); Copy Solution 5: Save the original_values @ document.ready. $(function(){ var original_values = $.map($('form input'), function(input){ return $(input).val() }); }) Copy Share You may like these postsIf Container Width, Padding And Line-height Is Known, How To Calculate Height?Get Value Of Html Cells In Row Clicked With JavascriptWhy Javascript Date.setdate() Change The Value Of Other Date Variables.load() Works In Ie And Dreamweaver Preview, But No Opera And Chrome Post a Comment for "JQuery: Get Original Input Value"
Post a Comment for "JQuery: Get Original Input Value"