I have a little question.
I am having a form field repeating in all rows which is coupled with a LIVE event to trigger a jQuery function.
Can I add an iteration here somehow? repetitive code is really not the thing I want…
$("#exampassed1").autocomplete({
source: "exams.php",
minLength: 2
});
$("#exampassed2").live('focus', function() {
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed3").live('focus', function() {
$("#exampassed3").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed4").live('focus', function() {
$("#exampassed4").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed5").live('focus', function() {
$("#exampassed5").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed6").live('focus', function() {
$("#exampassed6").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed7").live('focus', function() {
$("#exampassed7").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed8").live('focus', function() {
$("#exampassed8").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed9").live('focus', function() {
$("#exampassed9").autocomplete({
source: "exams.php",
minLength: 2
});
});
$("#exampassed10").live('focus', function() {
$("#exampassed10").autocomplete({
source: "exams.php",
minLength: 2
});
});
I was thinking of something like this for the elements after the first
$("#exampassed2", "#exampassed3").live('focus', function() {
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
or
$($("#exampassed2"), $("#exampassed3")).live('focus', function() {
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
or
$("#exampassed2"), $("#exampassed3").live('focus', function() {
$("#exampassed2").autocomplete({
source: "exams.php",
minLength: 2
});
});
none works perfectly… any clues anyone?
use a class instead of iterated ids