Dynamically assign table VALUE using SELECT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phub11
    New Member
    • Feb 2008
    • 127

    Dynamically assign table VALUE using SELECT

    Hi all,

    I've not had much luck getting any responses from my previous posts, but managed to figure stuff out. Now I'm really stuck! Any help at all would be great....

    I'd like to use a SELECT dropdown, and pass the value selected to the VALUE attribute of a table on the same page. The following is code which doesn't work!!!

    [HTML]<script type="text/javascript">
    function updateValue() {
    document.getEle mentById('RETUR N).value = document.getEle mentById('selec tField').value;
    }
    </script>
    [/HTML]-------------
    [HTML]<select name="condition s_list" id="selectField " onChange="updat eValue();">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>
    [/HTML]--------------
    [HTML]<span class="style1"> <span class="style5">
    <span style="color: rgb(255, 0, 0);">BOX1</span><input
    name="box1[]" value="RETURN" type="checkbox" >
    </span></span><br>
    [/HTML]
    Thanks!!!
    Last edited by acoder; Feb 9 '08, 12:07 PM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    document.getEle mentById() expects an id. You're trying to use a value instead. You've also forgotten the end quote after RETURN.

    Comment

    • phub11
      New Member
      • Feb 2008
      • 127

      #3
      Thanks for the reply!

      Being a total JS newbie, I tried using:

      id="RETURN" in the table, and passed it to a PHP script, which reports the value as "on", not the selected value.

      I also tried using document.getEle mentByValue... which didn't work.

      Sorry about being so naive, but I've still no idea.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by phub11
        passed it to a PHP script, which reports the value as "on", not the selected value.

        I also tried using document.getEle mentByValue... which didn't work.
        Only the checked checkboxes are passed to the PHP script. To get the values, loop over the array. document.getEle mentByValue doesn't exist.

        Comment

        • phub11
          New Member
          • Feb 2008
          • 127

          #5
          Thanks again for the reply!

          I'm a bit confused, as when this a a static table, if I select multiple cells with the same box type (i..e, box1 from random cells), but having different VALUE statements, this works fine when I print the box1 array in PHP.

          I've changed this using scriptaculous to a dynamic drag-and-drop routine, so that a single template is shown above the table. This is cloned as the template is dropped into a desired cell, but I want to change the VALUE to whatever is chosen in SELECT.

          I figure the above would equate to the static table I've described at the beginning (but allowing one to change VALUE). I might be going about this wrong, so could you give me a few pointers of how to do this?

          Thanks!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Did you add id="RETURN" to the checkbox like this:
            [html]<input name="box1[]" id="RETURN" value="RETURN" type="checkbox" >[/html]Remember that it also has to be checked. I assume it's checked and you're only changing the value.

            Comment

            Working...