SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS/Selectboxes and Forms

    I am trying to use the code below to limit access to a system we use where I work. The JS code seems to be working fine, however, when I submit the form, neither select box is submitted. It only returns the value for the submit button on the bottom. It is like the 2 select boxes don't exist. Can anyone see what the problem is? I found the JS code on a JS freeware site.

    Chris

    Code:
    <script LANGUAGE="JavaScript">
    <!--
    // Control flags for list selection and sort sequence
    // Sequence is on option value (first 2 chars - can be stripped off in form processing)
    // It is assumed that the select list is in sort sequence initially
    var singleSelect = true;  // Allows an item to be selected once only
    var sortSelect = true;  // Only effective if above flag set to true
    var sortPick = true;  // Will order the picklist in sort sequence
    
    // Initialise - invoked on load
    function initIt() {
      var selectList = document.getElementById("SelectList");
      var pickList = document.getElementById("PickList");
      var pickOptions = pickList.options;
      pickOptions[0] = null;  // Remove initial entry from picklist (was only used to set default width)
      selectList.focus();  // Set focus on the selectlist
    }
    
    // Adds a selected item into the picklist
    function addIt() {
      var selectList = document.getElementById("SelectList");
      var selectIndex = selectList.selectedIndex;
      var selectOptions = selectList.options;
      var pickList = document.getElementById("PickList");
      var pickOptions = pickList.options;
      var pickOLength = pickOptions.length;
      // An item must be selected
      if (selectIndex > -1) {
        pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
        pickOptions[pickOLength].value = selectList[selectIndex].value;
        // If single selection, remove the item from the select list
        if (singleSelect) {
          selectOptions[selectIndex] = null;
        }
        if (sortPick) {
          var tempText;
          var tempValue;
          // Sort the pick list
          while (pickOLength > 0 && pickOptions[pickOLength].value < pickOptions[pickOLength-1].value) {
            tempText = pickOptions[pickOLength-1].text;
            tempValue = pickOptions[pickOLength-1].value;
            pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;
            pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;
            pickOptions[pickOLength].text = tempText;
            pickOptions[pickOLength].value = tempValue;
            pickOLength = pickOLength - 1;
          }
        }
      }
    }
    
    // Deletes an item from the picklist
    function delIt() {
      var selectList = document.getElementById("SelectList");
      var selectOptions = selectList.options;
      var selectOLength = selectOptions.length;
      var pickList = document.getElementById("PickList");
      var pickIndex = pickList.selectedIndex;
      var pickOptions = pickList.options;
      if (pickIndex > -1) {
        // If single selection, replace the item in the select list
        if (singleSelect) {
          selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
          selectOptions[selectOLength].value = pickList[pickIndex].value;
        }
        pickOptions[pickIndex] = null;
        if (singleSelect && sortSelect) {
          var tempText;
          var tempValue;
          // Re-sort the select list
          while (selectOLength > 0 && selectOptions[selectOLength].value < selectOptions[selectOLength-1].value) {
            tempText = selectOptions[selectOLength-1].text;
            tempValue = selectOptions[selectOLength-1].value;
            selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;
            selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;
            selectOptions[selectOLength].text = tempText;
            selectOptions[selectOLength].value = tempValue;
            selectOLength = selectOLength - 1;
          }
        }
      }
    }
    -->
    </SCRIPT>
    </head>
    
    <body onLoad="initIt()">
    <pre><? print_r($_GET); ?></pre>
    <form method="get" name="authorizedList" action="authusers.php">
    <table align="left" border="0" cellpadding="0" cellspacing="0" width="500">
    	<tr>
    		<td align="center" colspan="3">
    		<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
    			<tr>
    				<td align="center">Users</td>
    				<td align="center">Authorized List</td>
    			</tr>
    
    		</table>
    		<br>
    		</td>
    	</tr>
    	<tr>
    		<td align="center">
    		<select name="users" ID="SelectList" size="9" name="SelectList">
    		<option value=A001396>STEPHANIE A</option>
    		<option value=A000150>E A</option>
    		<option value=A000403>JOHNELLA A</option>
    		<option value=A000454>GEORGE A</option>
    		<option value=A001734>KENNETH A</option>
    		<option value=A000634>STEVEN A</option>
    		<option value=A000622>MAURICE A</option>
    		<option value=A097543>JOYCE A</option>
    		<option value=A000944>RONNIE A</option>
    		</select></td>
    		<td><input type="button" value="->" onclick="addIt();"></input><br><input type="button" value="<-" onclick="delIt();"></input></td>
    
    		<td align="center">
    		<select name="PickList" id="PickList" size="9">
    		<option value="01sel">Selection 01</option>
    		<option value=A001767>SAMUEL T</option>
    		</textarea></td>
    	</tr>
    	<tr>
    		<td colspan="3" align="center"><br></td>
    	</tr>
    	<tr>
    		<td colspan="3" align="center"><input type="submit" name="submit" value="Authorize Users"></td>
    	</tr>
    </table>
    </form>

  2. #2
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I ran the code through DWMX and there are just a bevy of errors. (Go code syntax highlighting!) Some things involve SELECT tags with multiple NAME attributes, SELECT tags closed with TEXTAREA tags, very poorly structured tables and the fact that </input> tags don't exist. (INPUT doesn't get closed!)

  3. #3
    SitePoint Zealot CDitty's Avatar
    Join Date
    Feb 2000
    Location
    Memphis Tn
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm embarassed to say that the select tag and multiple name tags were my fault.

    Even with the errors above fixed, it still will not transfer the form variables.

    Chris

    btw...What's wrong with my tables? It's just a nested table.


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
  •