![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2005
Posts: 29
Rep Power: 0
![]() |
a little help on basic JS programming
hi guys, need your help again.. cant figure out whats wrong with my codes.. need so expert help.. Plese help me on the codes below. my validation dont seems to work. althought it work well at first. and i also want to make it mark the text fields that it will add a score when the user gets the ans correct.
The Codes: <HTML><HEAD><TITLE></TITLE> <SCRIPT language=javascript> <!-- function validation() { var mark="0"; var temp; if (form1.name.value == "") { alert("Please fill in appropriately"); return false; } if (form1.question.value = form1.answer1.value ) { mark++; }else{ return false; } /* var theone; if (document.form1.station[3].checked==true) { mark+=1; alert("Correct"); theone=i; return false; } */ form1.submit(); } --> </SCRIPT> </HEAD> <BODY> <FORM name=form1 action=test2.html method=post>Question 1 Answer: <INPUT size=40 name=question> <INPUT onclick=validation() type=button value=Submit></TD> <INPUT type=reset value=Reset></TD> <INPUT type=hidden value=9 name=answer1> </FORM></BODY></HTML> thanks guys... cheers |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
please use CODE tags
if (form1.question.value == "") {
alert("Please fill in appropriately");
return false;
}
if (form1.question.value == form1.answer1.value ) {
mark++;
}else{
return false;
}
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jun 2005
Posts: 29
Rep Power: 0
![]() |
i did insert code tag in my file. i have amended e validating part, but i still dont know how to keep track of the score. pls advice. thanks
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
HTTP is a stateless protocol, therefore you cannot simply carry values over from one page to another without using storage on the server or client. Without using server-side code, you are left to use cookies for storing and retrieving the mark information. So, you will create/set the cookie on page A and retrieve/update the cookie on page B, C, etc.
Google: JavaScript cookies - there are tons of examples out there p.s. I meant use the CODE tags when you post here... so your source code will be more readable and copyable (see how my source code looks in my first reply).
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|