Hello,
I am trying to implement a jquery technique and am having a problem.
The script produces a select drop down list for a 3 character language code with the last value as other. When other is selected, jquery should show a div that allows a user to input a new language code.
After selecting other, the div is not showing.
Can someone take a look at this?
Also, when coding jquery, should the coding include separate script tags for each of the functions which means calling the
$(document).ready(function()
again or is it better to combine them all under one set of script tags?
e.g. tooltips are separated from the hide/show below.
Thanks,
Peter
<script src="jquery.tools.min.js" type="text/javascript"></script>
<!-- jquery tooltips -->
<script type="text/javascript">
$(document).ready(function(){
// specifies div name, element[part of element]
//$("#dyna textarea[title]").tooltip({
$("#tips a[title]").tooltip({
position: "center right",
track: true,
predelay: 10,
delay: 50,
showURL: false,
offset: [5, 0],
effect: "fade",
fadeInSpeed: 400,
fadeOutSpeed: 200,
opacity: 0.9
});
$(this).hide("slow");
});
</script>
<script type="text/javascript" >
// for hide - display field based on select
$(document).ready(function() {
$.viewInput = {
'0' : $([]),
//THIS IS THE NAME OF THE DIV WRAPPING THE HIDDEN FIELD
'otherField' : $('#otherField'),
};
$('#101').change(function() {
// HIDES THE INPUT FIELD IF ANOTHER DROPDOWN ITEM IS SELECTED ONCE THE HIDDEN FIELD IS LOADED
$.each($.viewInput, function() { this.hide(); });
// SHOWS THE INPUT FIELD ITEM IF SELECTED
$.viewInput[$(this).val()].show();
});
});
</script>
if ($key == "101"){
print ("<div id=\\"$key\\">\
"); // for hide - display field based on select
// language display values
$select = "SELECT distinct lang FROM $db_name.$table_name order by lang";
$result = mysql_query($select) or die($errorinfo6);
// do select
print "<select id=\\"$key\\" name=\\"$key\\" value=\\"$value\\" class=\\"dropdown\\"
title=\\"use <b>other</b> to add new item\\" \\"> ";
// default empty to avoid user confusion
print '<option value=""></option>';
// populate drop down with values
while($row = mysql_fetch_assoc($result)) {
if( empty($row["lang"]) ) continue; // because nulls currently exist
print '<option value="'.$row["lang"].'">'.$row["lang"].'</option>';
}
// do input
print "<option value=\\"otherField\\"><b>Other</b></option>";
print "</select>
<div id=\\"otherField\\">
<input type=\\"text\\" id=\\"$key\\" name=\\"$key\\" size=\\"3\\" value=\\"$value\\" class=\\"textfield\\" />
</div>";
//print '</select>';
print '</div>'."\
";
}