2

I want to set hidden input value(username) based on client other input(email) in a form, then submit to server. (to make sure username equal to email)

However, the assignment to the hidden input is processed AFTER the form submitted. So 'username' is already None on server side.

<form id="altForm" action="" method="post">

<input type="hidden" name="username" id="id_username" maxlength="40" >

<input type="email" name="email" id="id_email" maxlength="40">

<input class="btn btn-primary pull-right" type="submit" value="Register" />
</form>

<script>

    $("#altForm").submit(function(e){
        e.preventDefault();
        var username = $("#id_email").val();
        $("#id_username").val(username);

    });

</script>
2
  • Why; if the values are the same in each do you really need the hidden input? Commented Apr 13, 2015 at 21:54
  • I may set hidden input value 'username' based on the value 'email'. For example, username='example' if email='[email protected]'. Commented Apr 15, 2015 at 0:04

1 Answer 1

1

I would do this serverside, but if you want it clientside you can also accomplish it like this:

$('#id_email').keyup(function() {
    $('#id_username').val($(this).val());
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.