LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2005, 01:32 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
httpd & javascript


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
 
Old 06-26-2005, 03:31 PM   #2
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
I cant tell if you did this or not, but in CGI you need to output TWO newlines after the header, in Perl I do this:

Code:
print "Content-type: text/html\n\n";
print "<html><body><p>the rest of my page....";
 
Old 06-26-2005, 10:14 PM   #3
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
Thanks to lowpro2k3. I followed your suggestion and made sure there is 2 consecutive "newline" but the result is the same.
 
Old 06-26-2005, 10:58 PM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Re: httpd & javascript

Quote:
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
 
Old 06-29-2005, 07:33 AM   #5
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
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.
 
Old 07-01-2005, 07:54 AM   #6
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
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

Hope this is useful to someone.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Arrays, checkboxes in javascript & PHP Elijah Programming 21 11-15-2004 11:37 PM
Mozilla & Javascript : Not displaying menu Maxwell Rain Linux - Software 0 10-02-2004 09:06 PM
JavaScript & PHP Gerardoj Programming 1 06-11-2004 12:02 AM
Javascript && Bookmark -- need help plz DaFrEQ Programming 7 10-09-2003 01:13 PM
iptables & httpd LAR12345 Programming 6 03-03-2003 04:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration