I did try to do this (with jQuery):
type = (blabla == blublu)? 'category':'regular';
(type+'Name').val('...');
this is the console response:
Uncaught TypeError: Object categoryName has no method 'val'
although they actually exist...
so how can I make it work??
edit:
this is the full function:
var type = (1 == 1)?'something':'blabla';
var somethingName = $('#somethingName');
var blablaName = $('#blablaName');
more variables like this..
function itemMode(mode, inputValue){
inputValue = (typeof inputValue !== 'undefined')? inputValue:'';
var functionName = null;
switch(mode){
case 'open':
btnValue = 'something';
functionName = editCategory; // this need to be from type to
openItem = true;
break;
case 'close':
btnValue = 'something';
functionName = addCategory; // this need to be from type to
openItem = false;
break;
default:
return false;
}
(type+'Name').val(inputValue);
$('#btn'+type.capitalize()).off('click').val(btnValue).click(functionName);
(type+'Name').off('keypress').keypress(function(e){enterPress(e,functionName);});
}
i try (type+'Name') to crate reference to an existing var or object.