jquery - Attach Javascript to Certain Form Field Autocomplete -
i have autocomplete script works great adding page multiple forms , wont work.
here js:
<script type="text/javascript" src="jquery/js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript"> jquery(document).ready(function(){ $('#zipsearch').autocomplete({source:'suggest_zip.php', minlength:2}); }); </script> <link rel="stylesheet" href="jquery/css/smoothness/jquery-ui-1.8.2.custom.css" /> <style type="text/css"><!-- /* style auto-complete response */ li.ui-menu-item { font-size:12px !important; } --></style> and form field is:
<form action="<?php echo $globals["webroot"]; ?>/index.php?action=<?php echo $globals["rfa"];?>" method="post" name="postform1"> <input name="locationid" type="text" class="span10" id="zipsearch"> i have tried:
jquery(document).postform1.ready(function(){ $('#zipsearch').postform1.autocomplete({source:'suggest_zip.php', minlength:2}); }); this test form in same folder page working on... works on test page
<html> <head> <title>test jquery autocomplete</title> <script type="text/javascript" src="jquery/js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery/js/jquery-ui-1.8.2.custom.min.js"></script> <script type="text/javascript"> jquery(document).ready(function(){ $('#zipsearch').autocomplete({source:'suggest_zip.php', minlength:2}); }); </script> <link rel="stylesheet" href="jquery/css/smoothness/jquery-ui-1.8.2.custom.css" /> <style type="text/css"><!-- /* style auto-complete response */ li.ui-menu-item { font-size:12px !important; } --></style> </head> <body> <form onsubmit="return false;"> enter city: <input id="zipsearch" type="text" /> </form> </body> </html>
add class of fields want autocomplete on:
<input name="locationid" type="text" class="span10 autocomplete" id="zipsearch"> <input type="text" class="span10 autocomplete"> <input type="text" class="span10 autocomplete"> then, change selector:
$(function() { $('.autocomplete').autocomplete({source:'suggest_zip.php', minlength:2}); });
Comments
Post a Comment