We help IT Professionals succeed at work.

Change JavaScript into CGI

Medium Priority
325 Views
Last Modified: 2013-12-25
here is my question:

I have made a javascript that will calculate prices for items that are checked in a form (used in a comapny store).  However, I want to support this store for non-javascript browser.  I need someone to help me convert this javascript into any language so that I can use CGI as an alternative to javascript once it gets up on the site.

thanks,

etienne
Comment
Watch Question

Author

Commented:
Adjusted points to 220
If you submit your current web page (Javascript code included), or give a URL to look at, i'll give you back a working CGI program written in C.

Rgds, julio

Author

Commented:
Julio,

here is the URL:

http://www.best.com/~lobo/order.html

I know c++, so I should have no problem understanding what you are doing, but just in case, could you document here and there?  Thanks.  Also, the JavaScript is not very efficient, but it's easy to add and substract items to buy from the list, maybe keep that in mind when you are doing the script.  If you do all this, I will up my point value for this question and give more points to you.

landslide
Hello,

i've looked at the Url, and it seems you have already got a cgi running... so i must be missing something.

What do you exactly need my CGI to do?
That nice interactive stuff you do with Javascript, just *cannot* be done with CGI, as i'm sure you know.

So, please, give me some more enlightenments.

A bientot, julio
icd

Commented:
I am very close to a complete answer to this. Look at the script at the following URL:

http://www.silkwood.co.uk/cgi-bin/order.pl

This carries out the exact function that your Javascript does, only server side and it does not require any Javascript to run.

It is written in perl.

You will notice however that there is one slight problem. There is no 'Order' button. This is because the form submits to itself in order to calculate the total order price. The only way I can think of having an order button at the moment requires Javascript, which would rather defeat the purpose :-(

If this is the sort of thing you want then reply to this message. Don't grade my answer until I have a complete solution, or someone else has a better solution. I am still working on it.

icd

Commented:
The script has now been changed. The only problem (if problem it is) is that the form.cgi script needs to be incorporated into the script I have produced. Hopefully it is written in perl in which case there should be no problem.

If you cannot incorporate your script in mine directly then you will have to call it from within my script.

Test out the script I have put up. If you want the source code then you can obtain it from

http://www.silkwood.co.uk/cgi-scripts/order.pl

Author

Commented:
This is what I want the CGI to do:

I just want it to add up the price of the items that are checked in the form, and print that price in the text window (basically just do what the order button is doing rigth now).

etienne

PS, don't mind the cgi script you go to when you click send, that was just a test from me.
icd

Commented:
Check out my test script then and let me know if it is OK.

http://www.silkwood.co.uk/cgi-scripts/order.pl


Author

Commented:
ICD,

how would I test your script?

etienne
icd

Commented:
run the script at

http://www.silkwood.co.uk/cgi-bin/order.pl

see if it gives the same calculation as your javascript does. If so then copy the script from

http://www.silkwood.co.uk/cgi-scripts/order.pl

into your own script directory and (assuming you have perl, which you have yet to confirm) modify my script to include the script you have already written in the part that says 'Do your order script processing here'.

Voila.

Author

Commented:
ICd,

I'm still not getting a correct feedback with your form.  Perhaps I need to explain it better:

The form has now change, it's a lot longer.  All I want it to do is take in the information, calculate how much the user must pay (based on what prodcuts they chose to buy, and how much of it).  Then the script prints out a new page that will have the total order and price printed out (so it will show the items bought, and for how much), then the user can click submit.

etienne
Commented:
The script at

http://www.silkwood.co.uk/cgi-bin/order.pl

Has been modified to your (new) specification and you should try it out.

You should be able to take my solution from here and customise it to your needs. Your specific questions have been answered.

Experts-exchange is not a full design and implementation service. If that is what you want then I am sure there are several experts who would be willing to quote you for this work. (Myself included)

However if there are further specific questions I can answer I will try to provide them as comments.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
icd,

great job, this is what i'm looking for.  However, if i grade your answer, then i will not be able to ask you some little questions regarding the script.  Any suggestions?  Your email perhaps?  BTW, how do I get your script off your server.

landslide
icd

Commented:
The script (as text) can be obtained from

http://www.silkwood.co.uk/cgi-scripts/order.pl

Hold off grading my answer for now if you have further questions, especially if it will get me an 'A' grade!

Author

Commented:
Hello,

your grade is worth an A, so I will keep grading it on hold.


etienne

Author

Commented:
icd,

can I put javascript into the perl script when it spits back out a web page?

etienne

Author

Commented:
icd,
when I try it on my system, I get a "Document contains no data" alert!  What does this mean?  How can I fix it.  I've set all teh permissions i've needed to.

etienne
icd

Commented:
1. Since you are outputting the html from a perl script, as far as the browser is concerned it is receiving a html document. The answer then is that yes you can put Javascript (or any other valid HTML) into your document. It does however get a bit more difficult to code however and you have to be careful of literalising quotes etc but it can be done.

2. You need world read, execute privilages on the executable (755 on Unix) on the script and directory within which the script runs.

Check also the first line of the script to ensure it has the correct path to the perl interpreter on your system.

When you get this type of error it pays to look in the error log to see what the system made of the error. The position of the error log varies between systems, you should ask your administrator where it is. On unix the 'tail' command is useful for looking at the last few lines of this file.

Author

Commented:
icd,

it's an NT system.... any more suggestions...



etienne
icd

Commented:
Try a very simple script. The equivalent of the 'hello world' program to see if that works.

--- cut here ---
print "Content-type: text/html\n\n";

print "<html><head></head><body>Hello world</body></html>\n";
--- end ---

If that does not work then you will need to check the configuration of your server. If it does... well, we can take it from there!


Author

Commented:
Great job, couldn't have asked for a better final answer.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.