473,408 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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=true;
box.style.backgroundColor='#EEEEEE') 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.backgroundColor = 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.elements[thisElem.name];
if (! currentGroup.length) {
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<currentGroup.length;i++) {
currentGroup[i].checked = false;
}
return false;
}
if (0x31 <= key && key <= 0x39 && currentGroup) { // 1-9
var idx = key - 0x31;
if (idx < currentGroup.length) {
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(){active(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.length;i++) {
if (elems[i].type.toLowerCase() != "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.onfocus();
document.onkeypress = snapkey;
}
</script>

And at the top of the HTML, it needs:

<BODY onload="init('theForm')">
<FORM id="theForm" name="theForm">
Jul 23 '05 #1
7 2119
On 3/9/04 10:28 am, Steve Wylie wrote:
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.


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
ph***********@virgin.net
(Please remove the "z"s if replying by email)
Jul 23 '05 #2
>
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>


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
Jul 23 '05 #3
Steve Wylie wrote:

Who wrote this? Have you nothing learned during this year?
vvvvvvvvvvvvvvv
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>


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.


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!
Jul 23 '05 #4
Steve Wylie wrote:

Who wrote this? Have you nothing learned during this year?
vvvvvvvvvvvvvvv
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>


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.


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!
Jul 23 '05 #5
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
Jul 23 '05 #6
Thomas 'PointedEars' Lahn wrote:
Steve Wylie wrote:

Who wrote this? Have you nothing learned during this year?
vvvvvvvvvvvvvvv


It appears to have been quoted and posted by Steve Wylie. Get some
common sense and that becomes obvious.
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>


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.

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?


"often is absent"? I find that a dubious claim.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7
Steve Wylie wrote:
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!


I am not Lasse, but ignore the PointedEars person, we are still
anticipating his exit from puberty.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason A. Thompson | last post by:
Dear Access Gurus, I have a database which I hoped to use to administer questionnaires, or rather that someone who knows nothing about Access could use to administer them. Each q'aire item is on...
3
by: Tom_F | last post by:
To comp.databases.ms-access -- I have a questionnaire for which I would like to design a MIcrosoft Access form. I understand that the proper Access table structure would be: Respondent_ID ...
0
by: Christian Zotter | last post by:
Hello NG, I am a student at UDA in Austria, Austrian Partner of International Universities. To finnish my study i have to do a final year project. I have choosen the topic 'Evaluation of low...
3
by: standon410 | last post by:
Hi, I'm trying to develop a questionnaire...basically a user can pick one of 5 questionnaires they want to use, and based on their choice, those questions will appear in their form. So the...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
7
by: javedna | last post by:
Hi guys Ive got a simple problem, im designing an online questionnaire and on submission the coding that I have used to validate whether a user has filled in all the questions is supposed to...
2
by: Vili | last post by:
Hi all I am having problems with creating an functional questionnaire with asp.net 2.0 and MSSQL 2005 database. I have a table with field id (key & auto int), clientId (int), QuestionId...
10
by: fishlab | last post by:
Hello I'm using visual basic 2005 and i'm really useless and completely stuck. i'm making a questionnaire with a track bar from 1-7 to collect reponses. I have three forms. The first form...
6
by: Lakesider | last post by:
Dear NG, I want to create a dynamic questionnaire/survey application with .NET / C#. I want to ask questions and have several answer types: Yes/No, 1-10, list of answers, eg. "Dog", "Bird" and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.