User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,532 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,888 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1889 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 1
Reputation: jvallee is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jvallee jvallee is offline Offline
Newbie Poster

Question pass value in cgi script to javascript

  #1  
Oct 9th, 2007
I am loading a perl script that creates 2 arrays - 1 with a list of id's for classes offered and another with # of students already registered for each class (from a flat file that already exists)

How can I reference the array values generated by the cgi scipt in javascript?

Overall task:
I have shopping cart function that uses a value called classid
I want to read the classid array genereated by perl script
If classid value in shopping cart function matches a classid value in classid array
get matching element in # of students already registered" array
When I say matching, I mean element number or index.
Message user that "nn" students have already registered for this class...

If javascript could open and read a file on my server... I probably would not need cgi script?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: pass value in cgi script to javascript

  #2  
Oct 10th, 2007
No, javascript on the client machine can't and is not made to read files on the server. It's a client side language though it can be very well used on your server (that would be something rare).

To pass values from your server variables to javascript, you would need to dynamically generate the javascript content. In Java, we can do something like this:

  1. /* Greet.jsp */
  2.  
  3. <html>
  4. <head>
  5. <script>
  6. /* Here I am fetching the user name from the session variable which
  7. * I set on the server. There has to be a similar API offered by Perl for
  8. * accessing server side variables. Since only plain HTML pages are served
  9. * to the client / user by the server after processing the server side
  10. * constructs, you get to see the value of the username assigned to
  11. * the javascript variable.
  12. */
  13. myName = '<%= session.getAttribute("username") %>';
  14.  
  15. function greet() { alert('Hello ' + myName); }
  16. </script>
  17. </head>
  18. <body>
  19. <input type="button" value="Click" onclick="greet();" />
  20. </body>
  21. </html>
Last edited by ~s.o.s~ : Oct 10th, 2007 at 1:07 pm.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC