Solution 1 :

Not sure what exactly this has to do with validation, but this is not how you set a value to a form element in jQuery:

$("#guestForm-email").value = "[email protected]"

This is:

$("#guestForm-email").val("[email protected]")

Solution 2 :

First of all you cant write this as

$("#guestForm-email").value = "[email protected]"

this is the correct syntax

$("#guestForm-email").val("[email protected]")

and try to do this in function that return true if the data is valid an call it in

<form onSubmit="return validate()">

Solution 3 :

I guess what you are trying to do is to validate the e-mail sent on the input text field using jQuery. You can use a reg expression for this within your button’s click event handler like so:

$(document).ready(function() {
    $("button[type=submit]").click(function() {
        if(/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test($("#guestForm-email").value)) {
            return $("#guestForm-email").value;
        } else {
            alert("Invalid E-mail");
        }
    }
}

Solution 4 :

I think you want to append text inside input:

$("#guestForm-email").val($("#guestForm-email").val()+"[email protected]")

Problem :

Here is the code;

<form data-test="loginForm-container" novalidate="" method="POST" enctype="multipart/form-data">
<div class="css-o5d3v1 e1ovefus2">
    <div data-test="guestForm-email-wrapper" class="e1ovefus1 css-yjv4po e1eu3ser1">
        <div class="css-gg4vpm e1eu3ser4">
            <label for="guestForm-email" id="guestForm-email-label" data-test="input-label" class="css-1k1vx4d e1eu3ser5">Email Address*</label>
        </div>
        <div class="css-1tpy6sb e1eu3ser7">
            <input data-test="guestForm-email" aria-invalid="true" aria-required="true" id="guestForm-email" type="email" name="email" aria-labelledby="guestForm-email-label" class="css-15uq4zo e1eu3ser9" value="" aria-describedby="guestForm-email-error">
        </div><span data-test="input-error" id="guestForm-email-error" role="alert" class="css-mf5akt e1eu3ser0">Please enter email address</span></div>
</div>
<button type="submit" data-test="guestForm-submitButton" class="e1ovefus0 css-1wqqz58 e1y6awi20"><span>Continue as Guest</span></button>

I tried doing;

$("#guestForm-email").value = "[email protected]"

but when submit it deletes the text in textfield.

I just need to learn how to validate it in JQUERY.

Can anyone help?

Thanks.

Comments

Comment posted by jsfiddle.net/khrismuc/549g7nhr

Strictly speaking it doesn’t delete the text; what happens is the form is sent, and the page reloads. (not stating the

Comment posted by David

@Bob: “validate” how exactly? Is it “deleting” when you submit the form, or is it

Comment posted by David

@Bob: Can you provide a more complete example? Neither your one line of erroneous JavaScript code, nor the one line in this answer, would delete a value nor prevent the form from submitting. There has to be more to whatever you’re doing.

Comment posted by zakaria dinar

if the page get refreshed and the inputs get empty then the the data are valide and you re good

Comment posted by Chigozie Orunta

That is a reg expression. It simply checks to see that what the user has enter is a valid e-mail address.

By