How do i declare a default value in a function? I have a simple function
Called in HTML like
[code=HTML]<input type="text" id="example_nam e" onblur="color_i nput('example_n ame');">[/code]
You will notice that the #2 parameter is missing in the html call. Sometimes i don't have it to send. in PHP i would just set the functions second param like token=''
How do i set a default param in a JS function?
Code:
function color_input(id,token){
if (!empty(token)){
document.getElementById(id).style.backgroundColor = '#2A2A2A';
document.getElementById(id).style.color = '#DDC58C';
}else{
document.getElementById(id).style.backgroundColor = '';
document.getElementById(id).style.color = '';
}
}
[code=HTML]<input type="text" id="example_nam e" onblur="color_i nput('example_n ame');">[/code]
You will notice that the #2 parameter is missing in the html call. Sometimes i don't have it to send. in PHP i would just set the functions second param like token=''
Code:
function color_input(id,token=''){}
Comment