Hello Everyone,
I posted this question earlier under creating Multiple choice quiz. Is
it possible to ignore something using javascript. What I am trying to
do is creating a multiple answer quiz. I have five choices out of
which user are supposed to choose 3 best choices. The user should get
feedback on the choices they make. I have been able to provide the
feedback for all the choices but my problem is I am also getting the
feedback on the unchecked answers. Is there any way to tell javascript
not to check unchecked answers.
I have used the following code to accomplish this:
function check(f,key){
var newhtml="";
key=key.replace(/^.*0/,"").substr(0,5);
for(var i=0;i<key.length;i++) {
if ((key.charAt(i)<"5")==f.elements[i].checked)
{
newhtml+= question.a[i] + "<br>Right.<br>";
}
else if ((key.charAt(i)>"5")==f.elements[i].checked)
{
newhtml+= question.a[i] + " <br>Wrong.<br>";
} else {return};
}
document.getElementById("tablet").innerHTML= newhtml;
Could anyone help me with what's wrong with this code. Any help would
be appreciated.
Thanks 6 1572
"Vandana Rola" wrote I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer quiz. I have five choices out of which user are supposed to choose 3 best choices. The user should get feedback on the choices they make. I have been able to provide the feedback for all the choices but my problem is I am also getting the feedback on the unchecked answers. Is there any way to tell javascript not to check unchecked answers.
I have used the following code to accomplish this:
function check(f,key){ var newhtml=""; key=key.replace(/^.*0/,"").substr(0,5); for(var i=0;i<key.length;i++) { if ((key.charAt(i)<"5")==f.elements[i].checked) { newhtml+= question.a[i] + "<br>Right.<br>"; } else if ((key.charAt(i)>"5")==f.elements[i].checked) { newhtml+= question.a[i] + " <br>Wrong.<br>";
Add two slashes in front the above line, and javascript will ignore it.
// newhtml+= question.a[i] + " <br>Wrong.<br>";
If this is not what you had in mind, post some more code or preferably an
url so we can get an idea of what actually happens and what exactly should
not happen.
Maybe you mean that if f.elements[i] is not checked, the loop should just
continue. In that case, put this after the for(var i... line:
if( ! f.elements[i].checked) continue;
HTH
Ivo
} else {return}; } document.getElementById("tablet").innerHTML= newhtml;
Could anyone help me with what's wrong with this code. Any help would be appreciated.
Thanks
Vandana Rola said: Hello Everyone,
I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript. What I am trying to do is creating a multiple answer quiz. I have five choices out of which user are supposed to choose 3 best choices. The user should get feedback on the choices they make. I have been able to provide the feedback for all the choices but my problem is I am also getting the feedback on the unchecked answers. Is there any way to tell javascript not to check unchecked answers.
I have used the following code to accomplish this:
function check(f,key){ var newhtml=""; key=key.replace(/^.*0/,"").substr(0,5); for(var i=0;i<key.length;i++) { if ((key.charAt(i)<"5")==f.elements[i].checked) { newhtml+= question.a[i] + "<br>Right.<br>"; } else if ((key.charAt(i)>"5")==f.elements[i].checked)
Change that last line to simply:
else
Vandana Rola wrote: I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript.
Is this a question.
[...] Is there any way to tell javascript not to check unchecked answers.
// if checkbox is checked
if (referenceToCheckBox.checked)
{
...
}
I have used the following code to accomplish this:
function check(f,key){ var newhtml=""; key=key.replace(/^.*0/,"").substr(0,5); for(var i=0;i<key.length;i++) { if ((key.charAt(i)<"5")==f.elements[i].checked) { newhtml+= question.a[i] + "<br>Right.<br>"; } else if ((key.charAt(i)>"5")==f.elements[i].checked) { newhtml+= question.a[i] + " <br>Wrong.<br>";
} else {return}; } document.getElementById("tablet").innerHTML= newhtml;
The check() method is AFAIS syntactically correct (yet the indentation and
spacing -- the Pretty Printing -- has potential for improvement) but I do
not see a line where the check() method is called and you have not provided
sufficient information of the data it is operating on. Besides, you are
mixing DOM Level 1+ (getElementById()) and proprietary DOM (innerHTML)
without testing which is error-prone:
<http://pointedears.de/scripts/test/whatami>
HTH
PointedEars
Thomas 'PointedEars' Lahn wrote: Vandana Rola wrote:
I posted this question earlier under creating Multiple choice quiz. Is it possible to ignore something using javascript.
Is this a question.
[...] Is there any way to tell javascript not to check unchecked answers.
// if checkbox is checked if (referenceToCheckBox.checked) { ... }
I have used the following code to accomplish this:
function check(f,key){ var newhtml=""; key=key.replace(/^.*0/,"").substr(0,5); for(var i=0;i<key.length;i++) { if ((key.charAt(i)<"5")==f.elements[i].checked) { newhtml+= question.a[i] + "<br>Right.<br>"; } else if ((key.charAt(i)>"5")==f.elements[i].checked) { newhtml+= question.a[i] + " <br>Wrong.<br>";
} else {return}; } document.getElementById("tablet").innerHTML= newhtml;
The check() method is AFAIS syntactically correct (yet the indentation and spacing -- the Pretty Printing -- has potential for improvement) but I do not see a line where the check() method is called and you have not provided sufficient information of the data it is operating on. Besides, you are mixing DOM Level 1+ (getElementById()) and proprietary DOM (innerHTML) without testing which is error-prone:
<http://pointedears.de/scripts/test/whatami>
Could you *please* explain, in your own warped world of thinking, how
getElementById and innerHTML have *ANY* thing to do with whats on the
page you reference? Which is browser detection based on userAgent strings?
Randy Webb wrote: Thomas 'PointedEars' Lahn wrote: <http://pointedears.de/scripts/test/whatami>
Could you *please* explain, in your own warped world of thinking, how getElementById and innerHTML have *ANY* thing to do with whats on the page you reference? Which is browser detection based on userAgent strings?
If you would have read it thoroughly, you would have known that it in fact
deals with differences in client-side object models and explains why those
cannot be covered with testing HTTP headers (or properties reflecting them)
or buzzword objects but only with feature tests prior to access.
PointedEars
In a message inscribed eternally in the scrolls of comp.lang.javascript
Thomas 'PointedEars' Lahn wrote incesantly about : Randy Webb wrote:
Thomas 'PointedEars' Lahn wrote:
<http://pointedears.de/scripts/test/whatami>
Could you *please* explain, in your own warped world of thinking, how getElementById and innerHTML have *ANY* thing to do with whats on the page you reference? Which is browser detection based on userAgent strings?
If you would have read it thoroughly, you would have known that it in fact deals with differences in client-side object models and explains why those cannot be covered with testing HTTP headers (or properties reflecting them) or buzzword objects but only with feature tests prior to access.
That is fine and dandy, but it doesn't answer the question. If the page
is about Object Detection, then you need to reconsider its layout and
explanations. It covers, mostly, the userAgent string and its flaws.
P.S. You still haven't accepted/denied my challenge to you about
accessing a page with anything but NS6.
--
Randy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nicolas Fleury |
last post by:
Hi all,
The part of the Python community that doesn't like @decorators needs to
unite behind an alternative syntax to propose to Guido. I suggest we
use this thread to try to do it. If you...
|
by: Rob Meade |
last post by:
Lo all,
I was just running through some code I was writing for a site and when it
came to the 'exact phrase' search type I wasn't sure whether that should run
through and ignore the words in the...
|
by: Matthew |
last post by:
Is there anyway to tweak this to ignore the function() only if the Tab
key is pressed?
onkeydown="javascript:function();"
|
by: macgyver |
last post by:
This is a strange question, and I think the answer is NO, but I am
asking anyway.
I am a member of a website which allows us to alter our member
profiles. Using css in the middle of the profile...
|
by: bradwiseathome |
last post by:
I do not want to disable a dropdown list, I want the selection to stay
on the same selection even if a user changes the option. I think I need
to trap mouseup and keyup or something, but I am not...
|
by: RSB |
last post by:
Hi
I am executing a JavaScript Function for a Button and doing some custom data
validation.
Now i want to Ignore the Button Click if the Data validation Fails. i am
using return(false) in the...
|
by: Jackson Miller |
last post by:
I notice that postgres does not support IGNORE.
I am currently migrating an app from a MySQL datastore to Postgres, and I
would really like to use IGNORE.
I am curious if there is a...
|
by: chanma |
last post by:
I have an num -569360386, and turn it into hex format.
I use toString(16),I get -21efc002.
But how can get 0xDE103FFE,which is to ignore the highest bit as the
signed bit?
|
by: samz |
last post by:
Hello,
Here is a simple PHP recursive file list (with interactive and visual FX)
Sam's Files
http://acc.jexiste.ch/JPN/RecurciveDIR12.RAR
1. How to ignore/avoid empty folders in this PHP script...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |