Autocomplete needing to clear fields if main field is changed.
New to the forum, great forum for a newbie by the way, so this may have been answered somewhere but couldn't find it.
I have the following code on my form.
- <script type="text/javascript" src="includes/jquery.js"></script>
- <script type='text/javascript' src='includes/jquery.autocomplete.js'></script>
- <link rel="stylesheet" type="text/css" href="includes/jquery.autocomplete.css" />
- <script type="text/javascript">
- $().ready(function() {
- $("#org_name").autocomplete("data.php", {
- width: 150,
- matchContains: true,
- mustMatch: false,
- selectFirst: false
- });
- $("#org_name").result(function(event, data, formatted) {
- $("#org_id").val(data[1]);
- $("#org_location").val(data[2]).attr("disabled",true);
- });
- });
- </script>
and this is the fields that are affected by this.
- <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
- <p><label for="org_name"><strong>Organization Name:</strong> </label>
- <input type="text" name="org_name" id="org_name" value="" />
- *
- </p>
- <p><label for="org_location"><strong>Organization Location:</strong> </label>
- <input type="text" name="org_location" id="org_location" value="" />
- <input type="hidden" name="org_id" id="org_id" value="" />
- <p>
- <input type="submit" name="button" id="button" value="Submit" />
- <input type="reset" name="button2" id="button2" value="Reset" />
- </p>
- <input type="hidden" name="MM_insert" value="form1" />
- </form>
Here is the code for the data.php page.
- $q = strtolower($_GET["q"]);
- if (!$q) return;
- mysql_select_db($database, $table);
- $sql = "select org_name, ID, location from organization where org_name LIKE '$q%'";
- $rsd = mysql_query($sql);
- while($rs = mysql_fetch_array($rsd)) {
- $cid = $rs['ID'];
- $cloc = $rs['location'];
- $cname = $rs['org_name'];
- echo "$cname - $cloc|$cid|$cloc\n";
- }
Now everything works great until I want to change the text in the org_name field. The other two fields, org_location and org_id, will retain the input and I would like them to clear. I am afraid that my users will make a mistake and choose a suggested outcome and then want to change it.
Being new to jquery, I am sure that there is something simple to fix this.
Thanks