Events fire multiple times
Hi guys,
I make a function when user click on input text field then input text field turn into red, and the there is select tag options where user can select its require mathmatic functions. Then user select any function from option in select tag then the switch statment run and goes in default case in default case i uses the jquery ui selectable tool for manipulating the data this case runs perfectly on each click and on each selection. but i have manual case where my code keeps firing the clicked text input field new value + previous click value. actually when i click on input text field and select manual function then the functiont run first time fine. but when i click on 2nd on 2nd input text field the manual case function holds previous input text value and the new one clicked text value. i don;t know what to do in this case i'm struck from last month.
[Here is my code]
(document).ready(function() {
$("input[name=valuecell1], input[name=valuecell2], input[name=valuecell3]").click(function(var1) {
var var1 = this.name;
var elem = "input[name=" + var1 + "]";
$("#excelfunctions").change(function(evt) {
var efVal = $("#excelfunctions").val();
switch (efVal) {
default:
//alert(elem);
$("#rangevalue, #clickvalue, #excelfunctions, #criteria, #truecell, #falsecell").css("border-color", "red");
$(".inputWidth").css('border-color', "#717171")
$(elem).css("border-color", "red");
$(function() {
$("#drag").selectable({
stop: function(event) {
var id = countE = 0, aEHighLight = [], aEHighLight2 = [];
$("#drag td.ui-selected").each(function() {
aEHighLight[countE] = $(this).attr('id');
aEHighLight2[countE] = $(this).text();
countE++;
});
//get last value from an array is start
Array.prototype.last = Array.prototype.last || function(count) {
count = count || 1;
var length = this.length;
if (count <= length) {
return this[length - count];
} else {
return null;
}
};
//get last value from an array is end
var lastValue = aEHighLight.last();
//get last value from an array is end
$("#rangevalue").attr('value', aEHighLight[0] + ':' + lastValue);
var cellValue = $("#rangevalue").val();
var eFunc = $("#excelfunctions").val();
var critCell = $("#criteria").val();
var trueCell = $("#truecell").val();
var falseCell = $("#falsecell").val();
//if (eFunc !== "blank") {
$.post("formulaAjaxCalc.php", {rangevalues: cellValue, excelfunctions: eFunc, criteria: critCell, truecell: trueCell, falsecell: falseCell})
.done(function(data) {
$(elem).attr('value', data);
});
// }
$(elem).css("border-color", "#424242");
$("#rangevalue, #clickvalue, #excelfunctions").css("border-color", "#C3C3C3");
$("select#excelfunctions")[0].selectedIndex = 0;
}
});
});
$("#showResult").click(function() {
var eFunc = $("#excelfunctions").val();
var critCell = $("#criteria").val();
var trueCell = $("#truecell").val();
var falseCell = $("#falsecell").val();
var clickCell = $("#clickvalue").val();
$.post("formulaAjaxCalc.php", {excelfunctions: eFunc, criteria: critCell, truecell: trueCell, falsecell: falseCell, clickcell: clickCell})
.done(function(data) {
$(elem).attr('value', data);
$("select#excelfunctions")[0].selectedIndex = 0;
});
});
break;
case "MANUAL":
$("#rangevalue, #clickvalue, #excelfunctions, #criteria, #truecell, #falsecell").css("border-color", "red");
$(elem).css("border-color", "red");
$(function() {
$("#drag").selectable({
stop: function() {
$("#drag td").one("click", function(){
cellID = this.id;
oldValue = $("#clickvalue").val();
if (oldValue !== "Use mouse to click value") {
storeVal = $("#clickvalue").val();
} else {
storeVal = "";
}
var cellText = $("#" + cellID).html();
cellValue = $(elem).val(cellText);
newVal = storeVal + cellID;
$("#clickvalue").remove();
$("#addFields").append('<input id="clickvalue" onfocus="changeme(this.name);" onblur="changemeback(this.name);" name="clickvalue" style="width:138px;" class="inputext" type="text" value="' + newVal + '" />');
$(elem).css("border-color", "#717171").attr('value', cellValue);
$("#clickvalue").css("border-color", "#E5E5E5").attr('value', newVal);
$("#excelfunctions").css("border-color", "#E5E5E5");
$("#showResult").click(function() {
var eFunc = $("#excelfunctions").val();
var critCell = $("#criteria").val();
var trueCell = $("#truecell").val();
var falseCell = $("#falsecell").val();
var clickCell = $("#clickvalue").val();
$.post("formulaAjaxCalc.php", {excelfunctions: eFunc, criteria: critCell, truecell: trueCell, falsecell: falseCell, clickcell: clickCell})
.done(function(data) {
$(elem).val(data);
$("select#excelfunctions")[0].selectedIndex = 0;
});
$("#clickvalue").remove();
$("#addFields").append('<input id="clickvalue" onfocus="changeme(this.name);" onblur="changemeback(this.name);" name="clickvalue" style="width:138px;" class="inputext" type="text" value="Use mouse to click value" />');
$("select#excelfunctions")[0].selectedIndex = 0;
});
});
}
});
});
break;
case "blank":
alert("Please Select Manual OR Functions !")
break;
}
evt.stopPropagation();
});
});
//end
[end code]
Thanks
Adil