torthbandt
torthbandt

Reputation: 11

Hidden input Value doesn't change using jQuery

I'm trying to change the VALUE of this little hidden input field:

<input name="Source" value="" type="hidden">

with this jQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>

    $(document).ready(function () {
        $input = $('input[name="Source"]');
        $input.attr({'value': 'Foo'});
        console.log($input.attr('value'));
    });

</script>

Console.log(); works perfectly, I see Foo, but when I view the page source, the 'value' remains blank.

Is there a gotcha I'm not following in jQuery or is it because it's a hidden type that won't refresh the value?enter code here

Upvotes: 0

Views: 948

Answers (1)

Dominik
Dominik

Reputation: 6313

When you change this with Javascript the source code is not altered but the copy of the source code in your browser (the DOM).

So you cannot see the changes in your source code but when you inspect the page you'll be able to verify the change. Hope this helps.

Upvotes: 3

Related Questions