Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function to populate a selectbox

    Hello! I desperately need a function that populates a selectbox from regular text-links, and is called like this:
    <a href="#" onClick="(myselectbox', '14', 'myoption');">blaha</a>

    ...when clicked, the value "14" and the option "my option" is added to the selectbox "myselectbox".

    There must also be
    -a possibility to remove options
    -a check in the function so that the same value isn't added twice.
    -a way to submit every value that has been added to the box (submit it as a commadelimited string I guess)

    And is there a way of creating the function so that it works for several boxes? Really thankful if someone can help!
    Last edited by viktor; 03-04-2003 at 01:52 PM.

  • #2
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, but if you so desparately need this functionality, perhaps you might need to part with some of that proverbial fat cash

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, anyone else? This script is supposed to move content between selectboxes... but it doesn't work, i get the error "document.choiceForm.BoxTo.length is null or not an object"... Please help!

    <html>

    <HEAD>
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function moveOver(BoxFrom,BoxTo)
    {
    var boxLength = document.choiceForm.BoxTo.length;
    var selectedItem = document.choiceForm.BoxFrom.selectedIndex;
    var selectedText = document.choiceForm.BoxFrom.options[selectedItem].text;
    var selectedValue = document.choiceForm.BoxFrom.options[selectedItem].value;
    var i;
    var isNew = true;
    if (boxLength != 0) {
    for (i = 0; i < boxLength; i++) {
    thisitem = document.choiceForm.BoxTo.options[i].text;
    if (thisitem == selectedText) {
    isNew = false;
    break;
    }
    }
    }
    if (isNew) {
    newoption = new Option(selectedText, selectedValue, false, false);
    document.choiceForm.BoxTo.options[boxLength] = newoption;
    }
    document.choiceForm.BoxFrom.selectedIndex=-1;
    }
    function removeMe(BoxFrom,BoxTo) {
    var boxLength = document.choiceForm.BoxTo.length;
    arrSelected = new Array();
    var count = 0;
    for (i = 0; i < boxLength; i++) {
    if (document.choiceForm.BoxTo.options[i].selected) {
    arrSelected[count] = document.choiceForm.BoxTo.options[i].value;
    }
    count++;
    }
    var x;
    for (i = 0; i < boxLength; i++) {
    for (x = 0; x < arrSelected.length; x++) {
    if (document.choiceForm.BoxTo.options[i].value == arrSelected[x]) {
    document.choiceForm.BoxTo.options[i] = null;
    }
    }
    boxLength = document.choiceForm.BoxTo.length;
    }
    }
    function saveMe(BoxFrom,BoxTo) {
    var strValues = "";
    var boxLength = document.choiceForm.BoxTo.length;
    var count = 0;
    if (boxLength != 0) {
    for (i = 0; i < boxLength; i++) {
    if (count == 0) {
    strValues = document.choiceForm.BoxTo.options[i].value;
    }
    else {
    strValues = strValues + "," + document.choiceForm.BoxTo.options[i].value;
    }
    count++;
    }
    }
    if (strValues.length == 0) {
    alert("You have not made any selections");
    }
    else {
    alert("Here are the values you've selected:\r\n" + strValues);
    }
    }
    // End -->
    </script>
    </HEAD>

    <!-- STEP TWO: Copy this code into the BODY of your HTML document -->

    <BODY>

    <center>
    <form name="choiceForm">
    <table border=0>
    <tr>
    <td valign="top" width=175>
    Move this content...
    <br>
    <select name="move1a" size=10 onchange="moveOver('move1a','move1b');">
    <option value=1>Company News
    <option value=2>Industry News
    <option value=3>Product Updates
    <option value=4>Product Specifications
    <option value=5>Order History
    <option value=6>Order Status
    <option value=7>Contacts
    <option value=8>Calendar of Events
    <option value=9>Scheduler
    <option value=10>Notes
    </select>
    </td>
    <td valign="top">
    ...over here
    <br>
    <select multiple name="move1b" style="width:150;" size="10">
    </select>
    </td>
    </tr>
    <tr>
    <td colspan=2 height=10>
    <input type="button" value="Remove" onclick="removeMe(move1a,move1b);">
    <input type="button" value="Get Selected Values" onclick="saveMe();">
    </td>
    </tr>
    </table>
    </form>
    </center>

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by vickers_bits
    sorry, but if you so desparately need this functionality, perhaps you might need to part with some of that proverbial fat cash
    some may call it extorsion
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

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