By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,556 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,556 IT Pros & Developers. It's quick & easy.

Variables, Javascript and CGI

P: 7
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. }
  19. function validUpd() 
  20. {
  21.  var f = document.forms[0];
  22.  f.action='/cgi-bin/SORCP002?UPD'; 
  23. f.submit();
  24. }
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. }
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=""
Here is the Html from the form that is calling it as well. (random useless html has been removed)

Expand|Select|Wrap|Line Numbers
  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>
  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%/">
  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>
  18. <INPUT TYPE="HIDDEN"  VALUE="/%pq$_itemno%/" NAME="pq%_itemno/%pq$_lineno%/">/%pq$_wbitmlnk%/
  20. <A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
  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>
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>
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.....
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
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
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

Post your reply

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