Passing username portion of email address to hidden field

Passing username portion of email address to hidden field

I'm trying to pass just the username portion of an email address to a hidden field. Here's what I got so far:

  1. jQuery(document).ready(function(){
  2. jQuery("form").bind('submit',function(e){
  3.   e.preventDefault();
  4.   var formEmail=jQuery("input[name=email]").val();
  5.   jQuery("input[type=hidden][name=hidden_email]").val(formEmail);
  6. alert(jQuery("input[type=hidden][name=hidden_email]").val());
  7. alert(formEmail);
  8. });
  9. });

  10. <form method="post" action="#">
  11. <input type="text" id="email"  name="email"/>
  12. <input type="hidden" id="hidden_email" name="hidden_email"/>
  13. <input type="submit" id="submit" class="button" value="Submit" />
  14. </form>