473,395 Members | 1,783 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,395 software developers and data experts.

pass javascript score to a hidden form field

How would I pass the student's final score to a hidden form field?

<script language="javascript" type="text/javascript">

<!--



var score = 0;

var answer = new Array("1","2","3","4","5","6","7","8");

//Check and display score

function check(){

for(i=0;i<answer.length;i++){
//answer.lenght is the lenght of the answer array (in this case 8 answers
if(document.myform.elements[i].value.toLowerCase()==answer[i]){

score++;

var p=i+1;

var str="showpicture"+p;

document.getElementById(str).style.visibility="vis ible";

}

else

{

if(document.myform.elements[i].value!=""){

document.myform.elements[i].value="Wrong!";

var p=i+1;

var str="showpicture"+p;

document.getElementById(str).style.visibility="hid den";

}

}

}

score = 0;

}

//-->

</script>

<form name="form1" method="post" action="">
<input type="hidden" name="hiddenField">
</form>
Nov 4 '06 #1
2 3381
r035198x
13,262 8TB
How would I pass the student's final score to a hidden form field?

<script language="javascript" type="text/javascript">

<!--



var score = 0;

var answer = new Array("1","2","3","4","5","6","7","8");

//Check and display score

function check(){

for(i=0;i<answer.length;i++){
//answer.lenght is the lenght of the answer array (in this case 8 answers
if(document.myform.elements[i].value.toLowerCase()==answer[i]){

score++;

var p=i+1;

var str="showpicture"+p;

document.getElementById(str).style.visibility="vis ible";

}

else

{

if(document.myform.elements[i].value!=""){

document.myform.elements[i].value="Wrong!";

var p=i+1;

var str="showpicture"+p;

document.getElementById(str).style.visibility="hid den";

}

}

}

score = 0;

}

//-->

</script>

<form name="form1" method="post" action="">
<input type="hidden" name="hiddenField">
</form>
It makes no difference whether an input is hidden or not. You set its value as you would any other input
document.myform.hiddenField.value = score;
Nov 4 '06 #2
It makes no difference whether an input is hidden or not. You set its value as you would any other input
document.myform.hiddenField.value = score;
Thanks, that worked. I'm new at Javascript and didn't know how to pass it to a regular form field either. I appreciate your help.
Nov 4 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: GavMc | last post by:
Hello I am new to internet programming and wonder if anyone can help me with this.... I am trying to pass a hidden field value on a form into another field on the form so that it can then be...
7
by: Andy | last post by:
Hi, I have a complicated question that I'm hoping someone can help me out with. I have a webpage that contains a plug-in. This plug-in can communicate/pass data with the webpage that contains it...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
5
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the textbox fine but how to pass the value of radio...
11
by: viki1967 | last post by:
Hidden field Hello my friends. This is a htm page that contains a form open in window popUp ( page daughter ). This form insert a value in the one hidden field called "tec", in other form...
5
by: quirk | last post by:
I am trying to write a script where a page is populated with some maths questions, user answers them (it's timed but I've left this bit out), gets results on same page and ajax takes their score,...
9
by: nicnac | last post by:
Hi, I'm self learning javascript - so any pointers are welcomed!! I have an issue passing a form and array from one function to another. I tried many variations ! I can't get this to work...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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 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.