dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Using variables in

  1. #1
    Join Date
    May 2012
    Posts
    1

    Using variables in

    Hello there! I am trying to ensure that users only tick one combobox for each question in a questionnaire. Each set of comboboxes is given a name based on the question it belongs to.

    To find out the amount of comboboxes there are for a given question I have been using document.questionnaire.1.length (where 1 is the name of every combobox in that set), however when I try and do it using the variable qnum it doesn't work at all.

    Code:
    function chkcontrol(j, qcount, qnum) {
    var total=0; 
    alert("number of boxes: " + document.questionnaire.[qnum].length);
    var question = document.questionnaire.[qnum].length;
    for(var i=0; i < question; i++){
    alert(qnum)  
    if(document.questionnaire.question[i].checked){
    total =total +1;}
    if(total > 1){
    alert("Please only choose 1 answer per question") 
    document.question[j].checked = false ;
    return false;
    }
    }
    }
    Any help would be much appreciated

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,687
    using radio groups instead can save your time

  3. #3
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Without seeing your form it's hard to be sure, but element names must not start with a digit.

    The syntax is: formReference[ elementNamePrefix + index ]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles