SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to fire an onchange function when data do not change

    Hi,
    I've a problem with this block of code:
    HTML:
    Code:
    <div id=sources>
    	Source1: <select id='source1'></select><br/>
    	Source2: <select id='source2'></select><br/>
    </div>
    JavaScript:
    Code:
    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,

  2. #2
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here the simpler version:
    Code:
    <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:
    Code:
    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

  3. #3
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

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

  4. #4
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Thank you. I've tried onclick but the event is fire too fast. Even no resource hasn't been choose yet.

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hmm, I'm really not sure what to suggest then.
    Could you maybe elaborate on what it is that you are trying to do?

  6. #6
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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,

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

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

  8. #8
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •