I am trying to implement client side validation using jquery form validator but I have followed the guide and also noted in googling the answer to my question that there can be clashes with prototype.js
I have added the line var JQuery = jQuery.noConflict();
into the bottom of my jquery-1.5.1.min.js
file.
Firebug is still saying
$("#contact") is null
$("#contact").validationEngine();
I have the required javascript and jQuery code loaded into my main page template.php file
witch then calls a view
called contact.
Contact Page View:
<section id="content" class="contact-us">
<h1>Contact</h1>
<div id ="formLayout" class="contactForm">
<section id = "validation"></section>
<form action=contact" method="post" accept-charset="utf-8" id="contact" name="contact">
<fieldset>
<label><label for="name">Name:</label><span class="small">Required Field - Text</span></label>
<input type="text" name="name" value="" id="name" class="validate[required[custom[onlyLetterSp]]]" />
<div id="error"></div>
<label><label for="email">Email:</label><span class="small">Required Field - yourname@example.com</span></label>
<input type="text" name="email" value="" id="email" class="validate[required[custom[onlyLetterSp]]]" />
<div id="error"></div>
<label><label for="phone">Phone:</label><span class="small">Required Field - 021214589</span></label>
<input type="text" name="phone" value="" id="phone" class="validate[required[custom[onlyLetterSp]]]" />
<div id="error"></div>
<label><label for="message">Message:</label><span class="small">Required Field - Text</span></label>
<textarea name="message" cols="90" rows="12" id="message" class="validate[required[custom[onlyLetterSp]]]" >
</textarea><div id="error"></div>
<input type="submit" name="submit" value="Submit" />
</fieldset>
</form>
</div>
</section>
</div>
<div class="clear"></div>
<footer>© Housemovers LTD 2011</开发者_如何学JAVAfooter>
</div> <!-- Wrapper Close -->
<script type="text/javascript" src="http://jesse.mckenzie.natcoll.net.nz/_Assignments/Industry/includes/js/jquery-1.5.1.min.js"></script>
<script src="/includes/js/lightbox/prototype.js" type="text/javascript"></script>
<script src="/includes/js/lightbox/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
<script src="/includes/js/lightbox/lightbox.js" type="text/javascript"></script>
<script src="includes/js/jquery.validationEngine-en.js"type="text/javascript"></script>
<script src="/includes/js/jquery.validationEngine.js"type="text/javascript"></script>
<script type="text/javascript">
JQuery(document).ready(function(){
$("#contact").validationEngine();
});
</script>
</body>
change it to
jQuery("#contact")
the .noConflict()
removes the $
binding to jQuery
If you have...
var JQuery = jQuery.noConflict();
...then...
$("#contact") is null $("#contact").validationEngine();
...will always be the case, as $
doesn't point to jQuery anymore. Try jQuery
or JQuery
there.
The latter one only works because you assigned the new identifier of jQuery to JQuery
. I wouldn't bother doing that personally, as jQuery
is consistent and your different case version will probably only lead to confusion.
精彩评论