Jump to content

Empty Function Paramaters


cesarcesar

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.