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 and I can't get this issue out of my head !!!!
So I'm obviously missing something really simple and can't see it or it can't be done with my limited knowledge.
I know that I can use a cookie to store the array as string - I have this working but I would like not to use cookies if possible.
ok my bare code:
- // sets up arrays
-
function generateQuestions(myNumberOfQuestionsAsked)
-
{ // myNumberOfQuestionsAsked is integer value
-
-
var realAnswers =new Array("0010","1010");
-
var answers = new Array();
-
-
for(i=0;i<myNumberOfQuestionsAsked;i++)
-
{ answers[i]= realAnswers[i]; }
-
displayQuestions(answers);
-
}
-
-
-
// creates the form in a table and uses the onclick to pass the form
-
function displayQuestions(answers)
-
{
-
..... within <BODY>
-
myTestWindow.document.write("<TABLE ID='testTable1'>");
-
// create the FORM
-
myTestWindow.document.write("<FORM ID='myForm' NAME='myForm'>");
-
-
// Create the HIDDEN element to hold the array
- myTestWindow.document.write("<INPUT TYPE='hidden' ID='mydata' NAME='mydata' VALUE=''>");
-
myTestWindow.document.write("</FORM>");
-
myTestWindow.document.write("</TABLE>");
-
-
myTestWindow.document.write("<INPUT TYPE='button' value='Mark Your Answers' onClick='testResults(myForm)'>");
-
//the next section is used to refresh the script
-
myTestWindow.document.write("<SCRIPT LANGUAGE='JAVASCRIPT' SRC='quizScript1.js'></SCRIPT>");
-
-
//take the array and put it in the hidden field in a string format
- ansString = unescape(answers.join())
-
myTestWindow.document.myForm.mydata.value=ansString;
-
-
...... closing tags<HERE>
-
}
-
-
// displays the hidden value
-
function testResults(myForm)
-
{
- alert ("You typed: "+myForm.mydata.value);
-
}
Any help would be appreciated!
Thanks!