ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a CGI script (let's call it script one) returning an HTML form that contains some javascript validation. This HTML form (let's call it script two) works well as an html page
but refuses to work when returned as a CGI script.
All that the javascript does in script two is check that one radio box is checked and then the form is submitted and call another, yet inexistant script (script three), HTTPD gives an expected "file not found" error that shows script two is not working when no radio box is checked.
I don't know what to look for, could anyone suggest how to solve this problem?
The scripts are written in assembly for speed but I would think anyone with CGI experience will spot the problem.
Thank you for your help.
Here is the code involved:
header db "Content-type: text/html",10,0
db 10
db "<SCRIPT LANGUAGE='JavaScript'>",10
db "function verify() {",10
db "var retval = false;",10
db "for(i=0;i<document.f1.L3.length;i++) {",10
db "if(document.f1.L3[i].checked == true) {",10
db "retval = true;",10
db "break;",10
db "}}",10
db "if(retval == false)",10
db "alert('Please select a State');",10
db "return retval;",10
db "}",10
db "</SCRIPT>",10
db "</head><body>",10
db "<form name='f1' action='http://192.168.1.13/cgi-bin/j2' method='post' onsubmit='return verify();'>",10
headerl EQU $ - header
states times 5120 db 0 ;radio boxes
statesl dd 0 ; length = bytes read
footer db "<input type='submit' value='Submit State now'></form></body></html>",10,0
footerl EQU $ - footer
Originally posted by rblampain This HTML form (let's call it script two) works well as an html page
but refuses to work when returned as a CGI script.
Can you explain this a bit further? Explain more about whats happening, errors that are occuring, post more code, are you using apache, etc...
Remember C code turns into assembly before it turns into object code. You dont have to make it so hard on yourself
Sometimes its better to prototype in a HLL, like Perl in this example. Also mod-perl is really quick because its a perl implementation compiled INTO apache. Just something to think about
Sorry for delay, I had to put this on the shelf for a couple of days.
The server is Apache 2. I use assembly because I find I am progressing faster with it than using other languages of which I have only a basic knowledge, I don't know Perl at all.
This script is checking that one "radio box" is checked and a 'javascript' alert (line 12) should appear if no box has been checked but this does not happen. If no radio box is checked, the script simply looks for the inexistant CGI.
What I have done is simple:
the part of the script involved reads a file, this file is a list of "<input type='radio.......etc'>" and put the contents of this file in "states" (4th line from bottom) and the length of the file is put into "statesl" (3rd line from the bottom.
The script as above is then returned as a CGI to the user who can select one of the "radio" boxes. When the new form is submitted, it calls a CGI routine that does not exist yet and therefore, Apache gives a ' file not found' error which shows that the script is executed.
When set up as a plain HTML page, the script above works.
The script above is returned in 3 blocks: header, states and footer. I thought this might be a problem and I recently changed the code to return these 3 parts in one block but this makes no difference to the end result.
Here is the code that returns the CGI:
mov eax,4
mov ebx,1 ;stdout
mov ecx,header
mov edx,headerl
int 0x80
mov eax,4
mov ebx,1
mov ecx,states
mov edx,statesl
int 0x80
mov eax,4
mov ebx,1
mov ecx,footer
mov edx,footerl
int 0x80
And here is the code holding the variables:
header db "Content-type: text/html"
db 10,10,0
db "<SCRIPT LANGUAGE='JavaScript'>",10
db "function verify() {",10
db "var retval = false;",10
db "for(i=0;i<document.f1.L3.length;i++) {",10
db "if(document.f1.L3[i].checked == true) {",10
db "retval = true;",10
db "break;",10
db "}}",10
db "if(retval == false)",10
db "alert('Please select a State');",10
db "return retval;",10
db "}",10
db "</SCRIPT>",10
db "</head><body>",10
db "<form name='f1' action='http://192.168.1.13/cgi-bin/j2' method='post' onsubmit='return verify();'>",10
headerl EQU $ - header
states times 5120 db 0
statesl dd 0 ; length = bytes read
footer db "<input type='submit' value='Submit State now'></form></body></html>",10,0
footerl EQU $ - footer
Thank you for your help.
Solution:
=======
I found the returned HTML did not work because the JS script could not find the elements called "L3" even though every "radio box" has "name='L3'" tag and this works as a plain html page.
Changing:
document.f1.L3.length
document.f1.L3[i].checked == true
to
document.f1.length
document.f1[i].checked == true
solved the problem
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.