SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    MD
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form/innerhtml/values not resetting.

    This is killing me.

    I have a muli-tabbed form, each with multiple selects. If more than three selections are made across all the tabs...an alert/confirm shows. Clicking "Ok" clears the form and innerhtml (or should). It looks like it does, but if you click "Ok" and then click on another tab and select another player...the values reappear.

    Take a look to get a better look at what I'm talking about


    Select more than three players from multiple tabs.
    Click ok on the prompt (it looks like it resets)
    Now click on another tab and select a player

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be because of this line?
    document.compareit.reset();

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your toomany() function actually can be simpler, made a simple sample here:
    HTML Code:
    <html>
    <body>
    
    <form id="compareit" onclick="testFunc()">
    
    	<select name="C" id="C" multiple="multiple">
    		<option value="C">C</option>
    		<option value="B">B</option>
    	</select>
    	
    	<select name="FB" id="FB" multiple="multiple">
    		<option value="FB">FB</option>
    		<option value="FFB">FFB</option>
    	</select>
    	
    	<select name="SB" id="SB" multiple="multiple">
    		<option value="SB">SB</option>
    		<option value="SSB">SSB</option>
    	</select>
    
    </form>
    
    <div id="testing"></div>
    
    <script type="text/javascript">
    
    // Predefine the full list of elements (square brackets == array literal, see link at end)
    var teams = document.getElementById('compareit');
    var compare_list = [ teams.C, teams.FB, teams.SB ];
    
    function testFunc() {
    
    	var test_div = document.getElementById('testing');
    	test_div.innerHTML = 'Length: '+compare_list.length+ '; ';
    	var totalselected = 0;
    	
    	for ( i=0; i<compare_list.length; i++ ) {
    	
    		if ( compare_list[i].value != '' ) {
    		
    			totalselected++;
    			test_div.innerHTML += '('+totalselected+')';
    			test_div.innerHTML += compare_list[i].value + ', ';
    		}
    	}
    }
    
    </script>
    
    </body>
    </html>
    I didn't check too closely, but your page missing some HTML tags.

    http://developer.mozilla.org/en/docs...Array_Literals

  4. #4
    SitePoint Member
    Join Date
    Oct 2004
    Location
    MD
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, abb. I'll test the new function out.

    As far as the original problem...I have yet to figure it out. I have a feeling it's something in here...

    Code:
    function set_selected_for_pos(list, pos) {
        var selec = '';
        for (var i = 0; i < list.options.length; i++) {
          
    	if (list.options[i].selected) {
    	    name = list.options[i].text;
    	    if(name) {
    		fname = name.substring(name.indexOf(',') + 2, name.length);
    		lname = name.substring(0, name.indexOf(','));
    		selec = selec + fname + ' ' + lname + ', ';
    	
    	    }
    	}
    
        }
    
        selec = selec.substring(0, selec.length - 2);
        position_list[pos] = selec;
    
    }
    I just have to figure out how to "undo" this if too many options are selected

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This seemed to work, its the global variable position_list, it did not reset when expected.
    Code:
    function add_player(list, pos) {
    ...
      if(confirm("You\'ve selected too many. 3 is the max!")) {
            
          document.compareit.reset();
            // reset position_list here
          position_list = new Array(positions_num);
      }

  6. #6
    SitePoint Member
    Join Date
    Oct 2004
    Location
    MD
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    abb...you are the man! Yes, that works like a charm!!

    I still haven't had a chance to test the new tooMany function you proposed, but I will today.

    Thanks again for your help!


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
  •