473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Variables, Javascript and CGI

Hi everyone, kinda new to Javascript.

Here is the issue, I have a form that sends to a different action based on the button pushed. But it also is sending variables to the server as well.

Here is the JS:

Expand|Select|Wrap|Line Numbers
  1. function validAdd()  
  2. {
  3.  var f = document.forms[0];
  4.  var error='N';
  5.  for (i = 0; i < qtyfield.length; i++)
  6.  {
  7.    if (!validate(qtyfield[i],i)){
  8.      alert('The quantity for item '+f[itmfield[i]].value+ ' should be in multiple of ' +      f[minqty[i]].value);
  9.      var error = 'Y'
  10.      break;
  11.      }
  12.  }
  13.  if (error != 'Y'){
  14. f.action='/cgi-bin/SORCP002?ADD'; 
  15. f.submit();
  16. }
  17. }
  18.  
  19. function validUpd() 
  20. {
  21.  var f = document.forms[0];
  22.  f.action='/cgi-bin/SORCP002?UPD'; 
  23. f.submit();
  24. }
  25.  
We are trying to change away from just ?ADD or ?UPD because every once and awhile the server seems to get confused.

Instead we are trying to do something more like

Expand|Select|Wrap|Line Numbers
  1. function validUpd() 
  2. {
  3.  var f = document.forms[0];
  4.  f.action='/cgi-bin/SORCP002?p_action=UPD'; 
  5. f.submit();
  6. }
  7.  
This way the parameters are set.

Unfortunately the CGI breaks down even worse. Am I supposed to declare the variable like

Expand|Select|Wrap|Line Numbers
  1. var p_action=""
  2.  
Here is the Html from the form that is calling it as well. (random useless html has been removed)

Expand|Select|Wrap|Line Numbers
  1. <FORM METHOD="POST">
  2.       <td class="orderpadmaint" height="30" align="center" width="20%"><a href="/cgi-bin/PQRCP010?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/" target="_blank">Add Items from MAIN</a></td>
  3.  
  4.  
  5. <INPUT TYPE="HIDDEN" NAME="dummyfield">
  6. <INPUT TYPE="HIDDEN" NAME="pq%_wbcsqno" value="/%pq$_wbcsqno%/">
  7. <INPUT TYPE="HIDDEN" NAME="pq%_sortmode" value="/%pq$_sortmode%/">
  8. <INPUT TYPE="HIDDEN" NAME="pq%_curpageno" value="/%pq$_curpageno%/">
  9. <INPUT TYPE="HIDDEN" NAME="pq%_pageno" value="/%pq$_pageno%/">
  10. <INPUT TYPE="HIDDEN" NAME="pq%_flrpageno" value="/%pq$_flrpageno%/">
  11. <INPUT TYPE="HIDDEN" NAME="pq%_totlines" value="/%pq$_totlines%/">
  12.  
  13.         <td Align="left"><A href="#" onClick="validAdd(); return false;"><IMG border="0" src="/_images/gen/ews_nav_qaddquotecart.jpg" width="186" height="27"></A></td>
  14.         <td Align="right"><A href="#" onClick="validUpd(); return false;"><IMG border="0" src="/_images/gen/ews_nav_qupdateorderpad.jpg" width="186" height="27"></A></td>
  15.             <A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
  16.  
  17.  
  18. <INPUT TYPE="HIDDEN"  VALUE="/%pq$_itemno%/" NAME="pq%_itemno/%pq$_lineno%/">/%pq$_wbitmlnk%/
  19.  
  20. <A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
  21.  
  22. <A href="#" onClick="validAdd(); return false;"><IMG border="0" src="/_images/gen/ews_nav_qaddquotecart.jpg" width="186" height="27"></A></td>
  23.         <td Align="right"><A href="#" onClick="validUpd(); return false;"><IMG border="0" src="/_images/gen/ews_nav_qupdateorderpad.jpg" width="186" height="27"></A></td>
  24. </form>
  25.  
Which also brings me to a secondary question along similar lines....

Expand|Select|Wrap|Line Numbers
  1. <A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
  2.  
We are trying to send variables this way in both html and Javascript.

neither one goes through right

Are we naming improperly? Are we supposed to plug the variables in as different way such as

Expand|Select|Wrap|Line Numbers
  1. 'p_wbcsqno='+/%pq$wbcsqno%/+'&p_sortmode.....
  2.  
Does a URL and variables sent from Javascript need any special consideration for the server to understand it and grab them?

Oh, and just fyi, we are using a cgidev2 system with an AS400. But I can't imagine it being that radically different.

Thank you for any help that can be given

(just a warning this has been cross-posted)
Sep 18 '06 #1
1 2092
acoder
16,027 Expert Mod 8TB
For the first problem, check if the CGI works when you set the form action manually without using JavaScript.

As for the second problem, you'll need to use the encodeURIComponent() function around each URI component to preserve the formatting, etc. or encodeURI() around the whole string.
May 13 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Craig L | last post by:
I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but...
2
by: Craig L | last post by:
This is a solution followup to a request for help posted on 11/04/03 at 12:51pm titled "Using ASP Variables". Here is how you can make ASP variables available for use in Javascript code. I hope you...
3
by: mr_burns | last post by:
hi, i was wondering if anybody could tell me when a function is called and variables are defined within that function, are the variables global where i can call and modify the variables in other...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
7
by: jab3 | last post by:
Does JavaScript have "static" variables. That is, as in C (or local in Perl)? How can I keep a variable in a JavaScript function that doesn't change from call to call? It may not make sense in...
1
by: stephane | last post by:
I have a problem which must be in this : print" <script type='text/javascript'> document.location.replace('http://127.0.0.1/add_task.php?req_id={$maxValue}&tk_request_name={$req_name}');...
8
by: mantrid | last post by:
Hello I have the following code, where clicking yh1r is supposed to move h1 10px down and update the value of yh1 by 20 each time its clicked. what the code actually does is NOT move h1 and...
3
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP...
0
by: rpjd | last post by:
Apache2 over XP Home, PHP5, PostgreSQL8.2 If this is not the correct forum for this, it can be reposted accordingly. I have php variables/arrays that I want to display in a php webpage. What I am...
3
by: q-rious | last post by:
Hello All, 1. I would like to pass some variables (x and y below) from Javascript to PHP, process them in PHP, and return some other variables (a abd b) back to Javascript. --(x,y)--...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.