Can't extract multiple values from select box

Discussion in 'JavaScript' started by asapcorp, Apr 14, 2007.

Thread Status:
Not open for further replies.
  1. #1
    Hi all,

    I have a multiline select box on an asp page which is populated with a list of music genres (hard-coded), the user can select up to 3 genres, and i'm trying to get it so that when they submit the form the values of the genres they selected are extracted to hidden form fields and sent to another page to be saved to a database.

    The problem I'm having is that it seems as though the first value in the list is the only one that is extracted when it is selected, if i select any other (single or multiple) then nothing is extracted. Can anyone see what I've done wrong?

    Note: g1,g2 and g3 are the names of the hidden form fields, and pEdit is the form name.
    <script type="text/javascript">
          function submitCheck(select){
            var p = 0;
            for(p; p<select.options.length; p++){
              if(select.options[p].selected){
                if(document.pEdit.g1.value==""){
                  document.pEdit.g1.value=select.options[p].value;
                }else if(document.pEdit.g2.value==""){
                  document.pEdit.g2.value=select.options[p].value;
                }else if(document.pEdit.g3.value==""){
                  document.pEdit.g3.value=select.options[p].value;
                }else{
                  alert('Please only select 3 genres');
                  return false;
                }
              }
              return true;
            }
          }
        </script>
    PHP:
     
    asapcorp, Apr 14, 2007 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Could we see the whole document?
     
    Logic Ali, Apr 15, 2007 IP
Thread Status:
Not open for further replies.