Gediminas Šukys
Gediminas Šukys

Reputation: 7391

Input doesn't add a value to a FORM when it is added by .html function

TEXT input is appearing in the form VISUALLY, but the value is not added to the FORM? only "somefield" has been added. Maybe I should bind it additionally?

<form action="/" method="get">
<input type="hidden" name="somefield" value="somevalue">
<div class="addfield"></div>
<input type="submit" value="Submit">
</form>

<script>
$(document).ready(function() {
    $('.addfield').html('<input type="text" name="TEXT" value="SOME">');
});
</script>

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

Upvotes: 0

Views: 23

Answers (1)

Ankur Mishra
Ankur Mishra

Reputation: 1296

You have to add your jquery cdn link before to your jquery code. So first do this:

<form>
<input type="hidden" name="somefield" value="somevalue">
<div class="addfield"></div>
<input type="submit" value="Submit">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('.addfield').html('<input type="text" name="TEXT" value="SOME">');
});
</script>

Upvotes: 1

Related Questions