Values from drop down box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boyindie86
    New Member
    • Jun 2007
    • 31

    Values from drop down box

    Hi

    I am trying to get the following code to work I believe it should work but i don't understand why it doesn't :(

    I am trying to get it to take words that have been placed into the accepted dropdown box, and place a semi-colon at the end of each word, so that I have a delimited list of words.

    Which I then wish to pass into to the URL, which would allow me to do the necessary processing on the words in my PHP scripts


    my code looks like the following

    Code:
    function createLinks()
    {
      var Values = '';
        var selectBox = document.getElementById('acceptwords').options;
        for(var i=0; i<selectBox.length; i++) { // Loop through the options.
          Values += selectBox[i].value + ";"; // Concatenate the option values into the Value string.
        }
        Values=Values.replace(/;$/,""); // Trim the leading semi-colon.
      window.location="http://www.asite.com?words="+Values;  
    }
    and i call it using the

    [HTML]
    <input type="button" value="Make Link" onClick="create Links()">
    [/HTML]

    any help would be greatly appreciated

    Boyindie
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    It should work. Show the code for the select element.

    Comment

    • boyindie86
      New Member
      • Jun 2007
      • 31

      #3
      Originally posted by acoder
      It should work. Show the code for the select element.
      What do you mean by the select element?

      The actual drop down box

      sorry i am new to javascript

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, the drop down box.

        Comment

        • boyindie86
          New Member
          • Jun 2007
          • 31

          #5
          the dropdown box looks like the following

          [HTML]<table border="0">
          <tr>
          <td>
          <select id="wordlist" name="sel1" size="10" multiple="multi ple">
          <option value="">Word List</option>
          </select>
          </td>
          <image src=""
          onClick="moveOp tions1();"/><br /><br />
          <image src="h"
          onClick="moveOp tions2();"/>
          </td>
          <td>

          </select>
          <input type="button" value="Make Link" onClick="create Links()">

          </td>
          </tr>
          </table>[/HTML]

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Where's the drop down box with id "acceptword s"?

            Comment

            • boyindie86
              New Member
              • Jun 2007
              • 31

              #7
              Originally posted by acoder
              Where's the drop down box with id "acceptword s"?
              Appologies

              I must of messed up the paste somehow

              this is my drop down box

              [HTML]<table border="0">
              <tr>
              <td>
              <select id="wordlist" name="sel1" size="10" multiple="multi ple">
              </select>
              </td>
              <td align="center" valign="middle" >
              <image src="http://right_arrow.png "
              onClick="moveOp tions1();"/><br />
              <image src="http:///left_arrow.png"
              onClick="moveOp tions2();"/>
              </td>

              <td>
              <select id="acceptWords " name="sel2" size="10" multiple="multi ple">
              </select>
              <input type="button" value="Create Links" onClick="create Links();">
              </td>
              </tr>
              </table>[/HTML]

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                JavaScript is case-sensitive. The element has an id of "acceptWord s" and you're looking for "acceptword s".

                Comment

                • boyindie86
                  New Member
                  • Jun 2007
                  • 31

                  #9
                  thats it working thank you

                  i can't believe i haven't noticed that after almost two days!

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Just a capital W, it was. Glad you got it working.

                    Comment

                    Working...