Variables, Javascript and CGI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paradox
    New Member
    • Sep 2006
    • 7

    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:

    Code:
    function validAdd()  
    {
     var f = document.forms[0];
     var error='N';
     for (i = 0; i < qtyfield.length; i++)
     {
       if (!validate(qtyfield[i],i)){
         alert('The quantity for item '+f[itmfield[i]].value+ ' should be in multiple of ' +      f[minqty[i]].value);
         var error = 'Y'
         break;
         }
     }
     if (error != 'Y'){
    f.action='/cgi-bin/SORCP002?ADD'; 
    f.submit();
    }
    }
    
    function validUpd() 
    {
     var f = document.forms[0];
     f.action='/cgi-bin/SORCP002?UPD'; 
    f.submit();
    }
    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

    Code:
    function validUpd() 
    {
     var f = document.forms[0];
     f.action='/cgi-bin/SORCP002?p_action=UPD'; 
    f.submit();
    }
    This way the parameters are set.

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

    Code:
    var p_action=""
    Here is the Html from the form that is calling it as well. (random useless html has been removed)

    Code:
    <FORM METHOD="POST">
    	  <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>
    
                            
    <INPUT TYPE="HIDDEN" NAME="dummyfield">
    <INPUT TYPE="HIDDEN" NAME="pq%_wbcsqno" value="/%pq$_wbcsqno%/">
    <INPUT TYPE="HIDDEN" NAME="pq%_sortmode" value="/%pq$_sortmode%/">
    <INPUT TYPE="HIDDEN" NAME="pq%_curpageno" value="/%pq$_curpageno%/">
    <INPUT TYPE="HIDDEN" NAME="pq%_pageno" value="/%pq$_pageno%/">
    <INPUT TYPE="HIDDEN" NAME="pq%_flrpageno" value="/%pq$_flrpageno%/">
    <INPUT TYPE="HIDDEN" NAME="pq%_totlines" value="/%pq$_totlines%/">
    
            <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>
            <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>
    			<A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
    
    
    <INPUT TYPE="HIDDEN"  VALUE="/%pq$_itemno%/" NAME="pq%_itemno/%pq$_lineno%/">/%pq$_wbitmlnk%/
    
    <A href="/cgi-bin/PQRCP005?p_wbcsqno=/%pq$_wbcsqno%/&p_sortmode=/%pq$_sortmode%/&p_curpage=/%pq$_pageno%/">/%pq$_pageno%/</A>
    
    <A href="#" onClick="validAdd(); return false;"><IMG border="0" src="/_images/gen/ews_nav_qaddquotecart.jpg" width="186" height="27"></A></td>
            <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>
    </form>
    Which also brings me to a secondary question along similar lines....

    Code:
    <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

    Code:
    '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)
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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 encodeURICompon ent() function around each URI component to preserve the formatting, etc. or encodeURI() around the whole string.

    Comment

    Working...