JavaScript function that needs to wait?

My JavaScript code needs to get data from a function. The function is returning the data. I know because I see it via a console.log. However, the data it returns is too late for the function that needs it. How do I make it wait for the data? In this case, I need the property defaultColor: to wait for the function getCol().

    <script type="text/javascript">
		
		function getCol(col) {
			var dcol = '#'+col;
			console.log('default color: '+dcol);
			return dcol;
		}

		Coloris({
		  el: '.coloris',
		  swatches: [
			'#264653',
			'#2a9d8f',
			'#3665f3',
			'#f4a261',
			'#e76f51',
			'#d62828',
			'#023e8a',
			'#0077b6',
			'#0096c7',
			'#00b4d8',
			'#48cae4',
			'#893783'
		  ],
		  defaultColor: getCol(),
		  onChange: function onChange(color) {
			  console.log(color);
		  },
		  inline: true

		});
		
		document.addEventListener('coloris:pick', event => {
		  console.log('New Color', event.detail.color);
		});
		
		document.addEventListener('change', event => {
		  console.log('New Opener', event.detail);
		});	
	

    </script>

Do you have access to the other function? Can you modify it?

That implies you do not have the ability to modify the other function. Probably we need more information. Are you familiar with HTML DOM Events?

I can modify the other function. All the code and even the caller. Note the caller is not a web app but a desktop app. I have some familiarity with the Dom. What other information would helpful? Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.