javascript - Error messages on contact form -
right now, i'm validating contact form using java/ajax, , generating error messages in javascript following
messages: { fname: "please fill in name", email: "your email contact you", subject: "please fill in subject of message", recipient: "please let know contact", message: "please fill out message", captcha: "please answer 2x3" }
which generates
<label class="error">the error message id</label>
.
i'm not sure how label generated, i'm wanted replace empty text inputs value of error message when it's not filled out.
i've tried using
fname.value = "the error message";
but doesn't seem work. ideas on how error message show within input instead of generating label?
form markup:
<form name="myform" id="myform" action="" method="post"> <fieldset> <label for="fname" id="name_label">first name</label> <input type="text" name="fname" id="fname" value=""> <label for="lname" id="lname_label">last name</label> <input type="text" name="lname" id="lname" value=""> </fieldset> <fieldset> <label for="email" id="email_label">email</label> <input type="text" name="email" id="email" value=""> <label for="phone" id="phone_label">phone number</label> <input type="phone" name="phone" id="phone" value=""> </fieldset> <fieldset> <label for="message" id="message_label">message</label> <textarea name="message" id="message" size="30" value=""></textarea> <label for="captcha" id="captcha_label">what's 2x3?</label> <input type="text" name="captcha" id="captcha" value=""> </fieldset>< input type="submit" name="submit" value="submit"> </form> <p> <img src="%3c?php%20echo%20get_template_directory_uri();%20?%3e/images/loader.gif" id="loading" alt="loader" name="loading"> </p> <div id="results"></div>
use following js:
document.myform.fname.value = messages_parent_obj.messages.fname;
i've put jsfiddle here: http://jsfiddle.net/dwywe/ (note wrapped messages
in parent object since snippet implied there one).
Comments
Post a Comment