How to fire an onchange function when data do not change

Hi,
I’ve a problem with this block of code:
HTML:


<div id=sources>
	Source1: <select id='source1'></select><br/>
	Source2: <select id='source2'></select><br/>
</div>

JavaScript:


var s1 = document.getElementById('source1')
  , s2 = document.getElementById('source2');
  
var select_sources = function() {
		var sourceX = s1.value;
		var sourceY = s2.value;
	var constraints = {
		x: {
			optional: [{sourceId: sourceX}]
		},
		y: {
			optional: [{sourceId: sourceY}]
		}
	};
	init(constraints);
};

var init = function(sourceInfos) {
	for (var i = 0; i != sourceInfos.length; i++) {
		var sourceInfo = sourceInfos[i];
		var option = document.createElement("option");
			option.value = sourceInfo.id;
	}
}

s1.onchange = select_sources;
s2.onchange = select_sources;

Provided that the sources values are generated and appended automatically by the system.

The problem: when there are only one value for both data sources there’s no method to fire the function.

Thank you,

Here the simpler version:


<div id=sources>
	Source1: <select id='source1'>
				<option value="volvo">Volvo</option>
			 </select><br/>
	Source2: <select id='source2'>
				<option value="honda">Honda</option>
				<option value="volvo">Volvo</option>
			 </select><br/>
</div>

JS:


var s1 = document.getElementById('source1')
  , s2 = document.getElementById('source2');
  
var select_sources = function() {
		var sourceX = s1.value;
		var sourceY = s2.value;
	var constraints = {
		x: {
			optional: [{sourceId: sourceX}]
		},
		y: {
			optional: [{sourceId: sourceY}]
		}
	};
	init(constraints);
};

var init = function(sourceInfos) {
	console.log(sourceInfos);
}

s1.onchange = select_sources;
s2.onchange = select_sources;

I want the function to fire when I select Option 1 from Source 1.

Thanks

Hi,

The onchange isn’t going to work, as the value of the select doesn’t change.
Why not just use onclick?

Hi,
Thank you. I’ve tried onclick but the event is fire too fast. Even no resource hasn’t been choose yet.

Hmm, I’m really not sure what to suggest then.
Could you maybe elaborate on what it is that you are trying to do?

Please use Chrome for Android check this URL: http://meldville.com/demo/broadcaster.php

I’m not able to switch between back and front phone’s cameras. Provided that WebSocket connection is established (it’s not stable).

I adapt the code from this: https://simpl.info/getusermedia/sources/

Thank you,

Hi,

Sorry, I don’t have Chrome for Android - I have Safari for IOS.
Anyone else?

Chrome for Windows. But that isn’t the point. You have to have 2 cameras on a computer to see it in action. I focus mainly on mobile.

Anyway, thanks for an attempt to help. I’ll find another way around.