cesarcesar Posted January 27, 2009 Share Posted January 27, 2009 How do i declare a default value in a function? I have a simple function 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 = ''; } } Called in HTML like <input type="text" id="example_name" onblur="color_input('example_name');"> 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='' function color_input(id,token=''){} How do i set a default param in a JS function? Link to comment https://forums.phpfreaks.com/topic/142712-empty-function-paramaters/ Share on other sites More sharing options...
trq Posted January 28, 2009 Share Posted January 28, 2009 function color_input(id,token){ if (!token) { token = ''; } } Link to comment https://forums.phpfreaks.com/topic/142712-empty-function-paramaters/#findComment-748092 Share on other sites More sharing options...
cesarcesar Posted January 28, 2009 Author Share Posted January 28, 2009 @thorpe - thanks much Link to comment https://forums.phpfreaks.com/topic/142712-empty-function-paramaters/#findComment-748374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.