Questionnaire form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Wylie

    #1

    Questionnaire form

    Last year a kind soul by the name of Lasse Reichstein Nielsen answered
    a question for me on this newsgroup, including a script that solved my
    problem. I now need to script to be slightly amended to take account
    of something, and I am posting this message in the hope that Lasse, or
    another equally talented reader, can help with this latest tweak to
    the script.

    On this newsgroup I asked for help with a questionnaire I was
    doing in HTML & Javascript. I wanted a script that allowed me to use
    the keys 1-9 to fill in the form rather than using the mouse (so where
    there was a selection of radio controls, I would hit 1 to select the
    first one, two for the second etc), and use Enter to move down the
    form.

    Lasse provided the script below, however sometimes there is a question
    with an option "Other" which people can tick then write their "other"
    response in the textarea below the question. Normally, the textarea is
    disabled and greyed out (using box.disabled=tr ue;
    box.style.backg roundColor='#EE EEEE') until someone ticks the "Other"
    box whereupon the box is enabled and they can type into it.

    Lasse's script comes up with an error when it jumps to one of these
    disabled boxes. Is there a way the script can be amended so that it
    would skip past any disabled boxes, or at least not come up with an
    error when it jumped to them?

    Hope you can help.

    Steve Wylie
    Canterbury
    United Kingdom




    <script type="text/javascript">
    var snapForm;
    var currentControl;
    var currentGroup;
    var nextControl

    function setTDBackground (elem,bg) {
    // find surrounding td elements
    var cnt;
    var tds = [];
    while(elem) {
    if (elem.tagName == "TD") {
    tds[tds.length] = elem;
    }
    elem = elem.parentNode ;
    }
    // if successful, set the background color of the td around
    // this answer.
    if (tds && tds.length>=2) {
    tds[tds.length-2].style.backgrou ndColor = bg;
    }
    }

    function active(thisElem ,nextElem) {
    setTDBackground (currentControl ,""); // clear previous highlight
    currentControl = thisElem;
    setTDBackground (currentControl ,"yellow"); // set new highlight
    nextControl = nextElem;
    if (thisElem.name) {
    currentGroup = thisElem.form.e lements[thisElem.name];
    if (! currentGroup.le ngth) {
    currentGroup = undefined;
    }
    }
    }

    function snapkey(event) {
    event = event || window.event;
    var key = event.keyCode || event.charCode || event.which;
    if(key == 0x30 && currentGroup) { // 0
    for (var i=0;i<currentGr oup.length;i++) {
    currentGroup[i].checked = false;
    }
    return false;
    }
    if (0x31 <= key && key <= 0x39 && currentGroup) { // 1-9
    var idx = key - 0x31;
    if (idx < currentGroup.le ngth) {
    currentGroup[idx].checked = true;
    }
    return false;
    }
    if (key == 13) {
    if(nextControl) {
    var next = nextControl;
    next.focus();
    next.onfocus();
    return false;
    }
    }
    return true;
    }

    function init(formName) {
    var makeActiveCall = function(next) {
    return function(){acti ve(this,next);} ;
    };
    var elems = document.forms[formName].elements;

    var firstElem; // first named element. Is focused at start.

    var currentName = "";
    var currentIdx = 0;
    for (var i=1;i<elems.len gth;i++) {
    if (elems[i].type.toLowerCa se() != "hidden" &&
    elems[i].name && currentName != elems[i].name) {
    if (!firstElem) {firstElem = elems[i];}
    for (var j = currentIdx; j < i; j++) {
    if (elems[j].name) {
    elems[j].onfocus = makeActiveCall( elems[i]);
    }
    }
    currentIdx = i;
    currentName = elems[i].name;
    }
    }
    for (j=currentIdx;j <elems.length;j ++) {
    elems[j].onfocus = makeActiveCall( );
    }
    firstElem.focus ();
    firstElem.onfoc us();
    document.onkeyp ress = snapkey;
    }
    </script>

    And at the top of the HTML, it needs:

    <BODY onload="init('t heForm')">
    <FORM id="theForm" name="theForm">
  • Philip Ronan

    #2
    Re: Questionnaire form

    On 3/9/04 10:28 am, Steve Wylie wrote:
    [color=blue]
    > Last year a kind soul by the name of Lasse Reichstein Nielsen answered
    > a question for me on this newsgroup, including a script that solved my
    > problem. I now need to script to be slightly amended to take account
    > of something, and I am posting this message in the hope that Lasse, or
    > another equally talented reader, can help with this latest tweak to
    > the script.
    >
    > On this newsgroup I asked for help with a questionnaire I was
    > doing in HTML & Javascript. I wanted a script that allowed me to use
    > the keys 1-9 to fill in the form rather than using the mouse (so where
    > there was a selection of radio controls, I would hit 1 to select the
    > first one, two for the second etc), and use Enter to move down the
    > form.[/color]

    What is the point of all this? Why don't you use access keys instead?

    Take a look here:
    <http://www.w3.org/TR/html401/interact/forms.html#h-17.11.2>

    --
    Philip Ronan
    phil.ronanzzz@v irgin.net
    (Please remove the "z"s if replying by email)


    Comment

    • Steve Wylie

      #3
      Re: Questionnaire form

      >[color=blue]
      > What is the point of all this? Why don't you use access keys instead?
      >
      > Take a look here:
      > <http://www.w3.org/TR/html401/interact/forms.html#h-17.11.2>[/color]

      Well, the point behind it is revealed from the paragraph in your
      article that says: "The invocation of access keys depends on the
      underlying system. For instance, on machines running Windows, one
      generally has to press the 'alt' key in addition to the access key."

      With Lasse's method, you don't.

      Steve

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Questionnaire form

        Steve Wylie wrote:

        Who wrote this? Have you nothing learned during this year?
        vvvvvvvvvvvvvvv[color=blue][color=green]
        >> What is the point of all this? Why don't you use access keys instead?
        >>
        >> Take a look here:
        >> <http://www.w3.org/TR/html401/interact/forms.html#h-17.11.2>[/color]
        >
        > Well, the point behind it is revealed from the paragraph in your
        > article that says: "The invocation of access keys depends on the
        > underlying system. For instance, on machines running Windows, one
        > generally has to press the 'alt' key in addition to the access key."
        >
        > With Lasse's method, you don't.[/color]

        With Lasse's method, you rely on the support of another technology,
        client-side scripting, which often is absent. How is this any better
        than using built-ins?


        PointedEars
        --
        Whoa There CowBoy! I Think We Got Us A Situation Here!

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Questionnaire form

          Steve Wylie wrote:

          Who wrote this? Have you nothing learned during this year?
          vvvvvvvvvvvvvvv[color=blue][color=green]
          >> What is the point of all this? Why don't you use access keys instead?
          >>
          >> Take a look here:
          >> <http://www.w3.org/TR/html401/interact/forms.html#h-17.11.2>[/color]
          >
          > Well, the point behind it is revealed from the paragraph in your
          > article that says: "The invocation of access keys depends on the
          > underlying system. For instance, on machines running Windows, one
          > generally has to press the 'alt' key in addition to the access key."
          >
          > With Lasse's method, you don't.[/color]

          With Lasse's method, you not only rely on the support of another technology,
          client-side scripting, which often is absent, but also take the risk of
          disabling common keyboard shortcuts. How is this any better than using
          the built-ins?


          PointedEars
          --
          Whoa There CowBoy! I Think We Got Us A Situation Here!

          Comment

          • Steve Wylie

            #6
            Re: Questionnaire form

            Because I don't want to have to (a) hold down the ALT key when
            inputting at speed, and (b) reformat by entire HTML form to
            accommodate the access keys method. Lasse's Javascript is
            self-contained and will just work with the form as it exists now.

            I'm just looking for a tweak to the existing script, not a full blown
            argument over the method!

            Lasse - are you out there mate?! PLEASE respond if you read this!

            Steve Wylie

            Comment

            • Randy Webb

              #7
              Re: Questionnaire form

              Thomas 'PointedEars' Lahn wrote:
              [color=blue]
              > Steve Wylie wrote:
              >
              > Who wrote this? Have you nothing learned during this year?
              > vvvvvvvvvvvvvvv[/color]

              It appears to have been quoted and posted by Steve Wylie. Get some
              common sense and that becomes obvious.
              [color=blue][color=green][color=darkred]
              >>>What is the point of all this? Why don't you use access keys instead?
              >>>
              >>>Take a look here:
              >>><http://www.w3.org/TR/html401/interact/forms.html#h-17.11.2>[/color]
              >>
              >>Well, the point behind it is revealed from the paragraph in your
              >>article that says: "The invocation of access keys depends on the
              >>underlying system. For instance, on machines running Windows, one
              >>generally has to press the 'alt' key in addition to the access key."
              >>
              >>With Lasse's method, you don't.[/color]
              >
              >
              > With Lasse's method, you rely on the support of another technology,
              > client-side scripting, which often is absent. How is this any better
              > than using built-ins?[/color]

              "often is absent"? I find that a dubious claim.


              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              • Randy Webb

                #8
                Re: Questionnaire form

                Steve Wylie wrote:
                [color=blue]
                > Because I don't want to have to (a) hold down the ALT key when
                > inputting at speed, and (b) reformat by entire HTML form to
                > accommodate the access keys method. Lasse's Javascript is
                > self-contained and will just work with the form as it exists now.
                >
                > I'm just looking for a tweak to the existing script, not a full blown
                > argument over the method!
                >
                > Lasse - are you out there mate?! PLEASE respond if you read this![/color]

                I am not Lasse, but ignore the PointedEars person, we are still
                anticipating his exit from puberty.


                --
                Randy
                comp.lang.javas cript FAQ - http://jibbering.com/faq

                Comment

                Working...