mjherbert
06-10-2004, 12:15 AM
onSubmit event handler refuses to send to CGI script and call function
--------------------------------------------------------------------------------
I have been having a few problems coding a Javascript quiz. I'm writing a Javascript quiz that, with the help of a CGI script, will save to a local text file. (Calling the CGI script by setting up a server on the local machine with Microweb). The quiz is entirely based on sequentially numbered images (i.e. 1,2,3,4). I've included the full code as a text file below; but essentially the sections that have been giving me grief are as follows:
function printQuestion(){
document.writeln('<H4 ALIGN = "LEFT"> Question ' +currentQuestion+ '</H4>')
document.writeln('<IMG ALIGN = "LEFT" src=' +currentQuestion+ '.jpg')
document.writeln('<FORM NAME ="answerForm" METHOD="POST" ACTION="../cgi-bin/csvwrite.pl" onSubmit="nextQuestion(); return false>" ')
document.writeln('<H4><BR><BR><BR><BR><BR><BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="1"> Grade 1<BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="2"> Grade 2<BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="3"> Grade 3<BR>')
document.writeln('<INPUT TYPE="Submit" NAME="Field' +currentQuestion+ '" VALUE="[ CSVwrite ]">')
document.writeln('</H4>')
document.writeln('</FORM>')
}
function nextQuestion(){
++currentQuestion
updateCookie()
location.reload(true)
}
To complicate matters I'm using a free CGI script: csvwrite.pl and microweb to test it out. For a reason that I am unable to understand, the onSubmit event handler refuses to post to the cgi script and call the nextQuestion() function. If I use onClick, I can call the nextQuestion() function, but I haven't found a way of submitting the form data to the CGI script. I am confident that the problem lies with my clumsily programmed Javascript; and I'm guessing it has to do with my usage of document.write. (I have successfully saved to the data file with a vanilla HTML form...) If anybody could help shed light on the problem, or recommend a work-around, it would be greatly, greatly appreciated...
-Mike
--------------------------------------------------------------------------------
I have been having a few problems coding a Javascript quiz. I'm writing a Javascript quiz that, with the help of a CGI script, will save to a local text file. (Calling the CGI script by setting up a server on the local machine with Microweb). The quiz is entirely based on sequentially numbered images (i.e. 1,2,3,4). I've included the full code as a text file below; but essentially the sections that have been giving me grief are as follows:
function printQuestion(){
document.writeln('<H4 ALIGN = "LEFT"> Question ' +currentQuestion+ '</H4>')
document.writeln('<IMG ALIGN = "LEFT" src=' +currentQuestion+ '.jpg')
document.writeln('<FORM NAME ="answerForm" METHOD="POST" ACTION="../cgi-bin/csvwrite.pl" onSubmit="nextQuestion(); return false>" ')
document.writeln('<H4><BR><BR><BR><BR><BR><BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="1"> Grade 1<BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="2"> Grade 2<BR>')
document.writeln('<INPUT TYPE="RADIO" NAME="Field' +currentQuestion+ '" VALUE="3"> Grade 3<BR>')
document.writeln('<INPUT TYPE="Submit" NAME="Field' +currentQuestion+ '" VALUE="[ CSVwrite ]">')
document.writeln('</H4>')
document.writeln('</FORM>')
}
function nextQuestion(){
++currentQuestion
updateCookie()
location.reload(true)
}
To complicate matters I'm using a free CGI script: csvwrite.pl and microweb to test it out. For a reason that I am unable to understand, the onSubmit event handler refuses to post to the cgi script and call the nextQuestion() function. If I use onClick, I can call the nextQuestion() function, but I haven't found a way of submitting the form data to the CGI script. I am confident that the problem lies with my clumsily programmed Javascript; and I'm guessing it has to do with my usage of document.write. (I have successfully saved to the data file with a vanilla HTML form...) If anybody could help shed light on the problem, or recommend a work-around, it would be greatly, greatly appreciated...
-Mike