add to select-ok but on submit nothing is selected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amzul
    New Member
    • Oct 2007
    • 130

    add to select-ok but on submit nothing is selected

    hello all,
    i have a small problam. i did 2 select list src and target.
    pressing on the add button move the selected src to the target
    everything is good and working untill i try to submit the target selectlist.

    it looks like nothing is selected

    is there any properties to mark it as selected i mean:
    not like that
    [HTML]<option value="x">xxxxx </option>[/HTML]
    need to b like that :

    [HTML]<option value="x" selected>xxxxx</option>[/HTML]
    so when i post it it will send to the mysql db

    sorry about the bad english and spelling

    thanks for the help
    Last edited by acoder; Oct 15 '07, 06:43 PM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    Use the selectedIndex property of the target list select element and set it to the option that requires selecting.

    Comment

    • Amzul
      New Member
      • Oct 2007
      • 130

      #3
      thanks for the welcoming
      all the target select list is need to be "selected"
      i was thinking on a for loop to select them all
      asoming x is the target id

      [CODE=javascript]function select_all_targ et(x)
      {
      y = document.getEle mentById(x);

      L = y.length;
      for(i=0;i =L; i++){
      x.options[i].selected
      }
      document.x.subm it();
      }[/CODE]
      that still send 'nulls' to my db
      i dont understand why the 'selected' propertie is selecting nothing ?
      Last edited by gits; Oct 16 '07, 06:34 AM. Reason: added code tags

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        hi ...

        have a look at your fixed example, note the changes ...

        1. wrong loopin condition
        2. the select-node is y instead of x
        3. set the selected property to 'true'
        ...

        [CODE=javascript]<html>
        <head>
        <script typ="text/javascript">
        function select_all_targ et(x) {
        y = document.getEle mentById(x);

        L = y.length;

        for(i=0; i < L; i++){
        y.options[i].selected = true;
        }
        }
        </script>
        </head>
        <body>
        <form name="myform">
        <select multiple size="3" id="sel">
        <option>test1 </option>
        <option>test2 </option>
        </select>
        <input type="button" value="select all" onclick="select _all_target('se l');"/>
        </form>
        </body>
        </html>
        [/CODE]
        kind regards

        Comment

        • Amzul
          New Member
          • Oct 2007
          • 130

          #5
          thanks gits for the condition and the rest
          it helps i can send to the db the values but its not looking good,
          i will maybe try to put the submit somewwhere alse

          p.s

          can anyone tell me what the right syntax for moving the from src to target in other broswer beside IE ?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by Amzul
            thanks gits for the condition and the rest
            it helps i can send to the db the values but its not looking good
            What's not looking good?
            Originally posted by Amzul
            can anyone tell me what the right syntax for moving the from src to target in other broswer beside IE ?
            Post the current code so we can suggest changes.

            Comment

            Working...