Click to See Complete Forum and Search --> : how to do this?


Tereno
10-25-2003, 07:41 PM
Hey guys! I want to make sort of a website that has a test on it so i'm goin to be putting out questions..
so i'd like a textbox and a submit button beside it..
then i would like to know if there's a script that can check that contents of the textbox and tell the person doing the test if it's the correct answer or not..
i have like 13 questions and i would not link to another page..can it be done on the page itself?...

Shampie
10-25-2003, 09:12 PM
function check_anwser{
var myanwser = hyper;
if(anamehere.value == myanwser){
alert("correct");
}else{
alert("that is incorrect");
}
}



in the button tag add: onClick="check_anwser()"
in the textbox tag add: name="anamehere";

so now when you type 'hyper' (no 's!) in the textbox and click the button it should say correct, else it will give 'that is incorrect'.

you are using 13 question orso, I would suggest using arrays to keep your script smaller and better readable.

Jona
10-25-2003, 09:24 PM
Shampie, are we forgetting something?

Two parentheses, (), must follow the name of the function:


function check_answer(){


;)
[J]ona

Shampie
10-25-2003, 09:56 PM
about that part,

sometimes I see functions like function blaat(moose, elk){

alert("you clicked the "+moose+" button, you get "+elk+" point(s)")

}

does this mean when I use an action like this:
(button with caption 'green') onClick="blaat(green, 1)"
(button with caption 'red') onClick="blaat(red, 2)"
when pressing the 'red' button it will return 'you clicked the red button , you will get 2 point(s)'
and when pressing the 'green' button it will return 'you clicked the green button , you will get 1 point(s)' right?

how is this called?

Jona
10-25-2003, 10:03 PM
No, it will not work because you must have 'green' and 'red' in quotes when you pass it to the function, otherwise it is seen as a variable and that variable does not exist.


function disp(obj,num){
alert("Object name: "+obj+"\nNumber:"+num);
}


Form buttons


<button onclick="disp('Cucumber',5);">Cucumber</button>


Numbers do not need to be passed as strings, because they are a different type of data and are processed differently.

[J]ona

Shampie
10-25-2003, 10:14 PM
so putting the colors into quotes will make it work ..

(button with caption 'green') onClick="blaat('green', 1)"
(button with caption 'red') onClick="blaat('red', 2)"
not using "'s because that will give an error -> "blaat(" is not an object...

learning by bits,

I am gratefull for your patience and time Jona and to anyone else who help others.

Jona
10-26-2003, 12:20 AM
Yes, that will work.

[J]ona