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? Quote Link to comment 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 = ''; } } Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted January 28, 2009 Author Share Posted January 28, 2009 @thorpe - thanks much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.