Link to home
Start Free TrialLog in
Avatar of garethtnash
garethtnashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

JQuery include Form Parameter in output

Hello, I have a form that returns an error if the submit action fails.

The form is
<form action="" method="post" name="Register" class="fancyform" id="Register">
  <h3>Register</h3>
    <div class="notify">Please complete the form below and click 'Register'</div>
    <div class="alert" id="RegisterError" style="display:none;"></div><div class="halfbox">
    <label for="regfirstname">First name</label>
    <input name="regfirstname" type="text" required="required" id="regfirstname" form="Register" placeholder="First name" value="" maxlength="50" /><br/>
    </div>
    <div class="halfbox">
    <label for="regfirstname">Last name</label>
    <input name="reglastname" type="text" required="required" id="reglastname" form="Register" placeholder="Last name" maxlength="50" /><br/>
    </div>
    <div class="halfbox">
    <label for="regfirstname">Email</label>
    <input name="regemailaddress" type="email" required="required" id="regemailaddress" form="Register" placeholder="e.g joe.bloggs@yahoo.co.uk" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" maxlength="135" /><br/>
    </div>
    <div class="halfbox">
    <label for="regfirstname">Password</label>
    <input name="regpassword" type="password" required="required" id="regpassword" form="Register" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" maxlength="50" /><br/>
    </div>
    <div class="labeldiv">
      <label title="Tick this option to have this computer / device store your login credentials">
                                                <input type="checkbox" name="rememberme" value="true" checked="checked">
                                                Remember me
      </label>
    </div>
    <input name="Register" type="submit" disabled="disabled" id="RegisterSubmit" form="Register" value="Register" />
  <input name="Cancel" type="button" class="cancelbutton closefb" id="RegisterCancel" onclick="$.fancybox.close()" value="Cancel" form="Register" />
  <input type="hidden" name="returnUrl3" value="">
</form>

Open in new window


The JQuery is

  $("#Register").submit(function(e){
      e.preventDefault();
    $.ajax({
		type: "POST",
        url: "/actions/register.asp",
        data:$(this).serialize(),
		success:function(result){
          if(result==2){
            // do something success
     		 $.fancybox.close();
			 location.reload();
          }else {
            // do something fail
	      $('#RegisterError').html('<p>An account already exists with the username XXXXX. Please either <a class="fancybox" href="#SignIn" rel="nofollow">Login</a> or <a class="fancybox" href="#PasswordRequestfrm" rel="nofollow">Reset your password</a></p>');
          $('#RegisterError').fadeIn('slow');
          }
  	  }});
  });

Open in new window


I want the section

$('#RegisterError').html('<p>An account already exists with the username XXXXX. Please

to replace the XXXXX with the form parameter value regemailaddress

Is this possible?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of garethtnash

ASKER

Great - thank you
You are welcome.