...

View Full Version : Minimizing code.



Scriptdaemon
01-10-2007, 02:59 AM
I can't quite figure out how to compact a few of the functions I use. For example, I wish to put these two functions into one and make them less dependent on the ID of the parent of the link that calls them. I've tried using this.parentNode as a parameter of the function and also used parentNode inside the function itself with "this" simply being one of the parameters, but I apparently don't understand the use of it very well.


function editName(number) {
if(edited)
return;
edited = true;
var nameTd = document.getElementById("nameTd" + number);
nameTd.style.padding = "0px";
nameTd.innerHTML = "<input id=\"nameInput\" onblur=\"saveName(" + number + ");\" " + trigger + "=\"if(isEnter(event)) { saveName(" + number + "); }\" type=\"text\" value=\"" + rows[number].name + "\" />";
document.getElementById("nameInput").select();
}
function editTitle(number) {
if(edited)
return;
edited = true;
var titleTd = document.getElementById("titleTd" + number);
titleTd.style.padding = "0px";
titleTd.innerHTML = "<input type=\"text\" id=\"titleInput\" onblur=\"saveTitle(" + number + ");\" " + trigger + "=\"if(isEnter(event)) { saveTitle(" + number + "); }\" value=\"" + rows[number].title + "\" />";
document.getElementById("titleInput").select();
}

The full code can be found here: http://moth.homelinux.com/~scriptdaemon/js/inventory.js



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum