-3

For example I have a code input name="username" with value="Yoga" and id="username" but it was not shown on the form and will be added automatically when the form is sent.

What this possible?

Widget 88
  • 5
  • 1
  • 3
    Possible duplicate of [jQuery - add additional parameters on submit (NOT ajax)](http://stackoverflow.com/questions/2530635/jquery-add-additional-parameters-on-submit-not-ajax) – showdev Jan 27 '16 at 22:09

1 Answers1

0

Please use this code.

<form id="test">

    <input type="text" id="username" name="username">
    <input id="button" type="submit" value="Submit">

</form>

<script>
$('#button').click(function() {

  if ($("#username").val() =="") {
    $('#username').val("Yoga") && 
      $('#test').submit();
  }
else {
  alert ("Access Denied!!")
    return false
  }
});
</script>

If the input will be filled out Access Denied and if left blank will produce a value of Yoga.

You can also use type="hidden" for a more perfect.

KS FIDDLE

Kangsigit
  • 54
  • 6