Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Submitting a form with a link using javascript

    I have many links on my cgi tool that has links like the following:

    http://localhost/cgi-tm/prod-def/org...re&AllowEdit=1

    But I dont want the users seeing the variables passed to my script.

    Can I use javascript to do this?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes you can use javascript to do that but it'd be a whole lot simpler to change the form tag from <form ... method="get"> to <form ... method="post">. You also have to change the server side script you're calling to accept it's input from the POST mechanism instead of the GET one.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can create a hidden form in the page that the javascripts posts to. Make sure the action is a POST, not a GET and you will not see the variables passed along the uri. This can become a pain, if there is a list of items, but it can be worked around.

    Code:
    <form name="temp" method="post" action="http://localhost/cgi-tm/prod-def/organize/training_wizard.pl">
    <input type="hidden" name="vsCOM" value="EDIT_TUTORIAL">
    <input type="hidden" name="Tutorial" value="Intro_to_Wildfire">
    <input type="hidden" name="AllowEdit" value="1">
    </form>
    
    <a href="javavscript:document.temp.submit()">Link</a>
    if each link needed something special, you could pass that to the form through a function that also submits the form

    Code:
    <a href="javascript:void(0)" onClick="javavscript:setPage('EDIT_TUTORIAL', 'Intro_to_Wildfire', '1')">Intro to Wildfire</a>
    <script>
    function setPage(a,b,c){
    document.temp.vsCom = a;
    document.temp.Tutorial = b;
    document.temp.AllowEdit = c;
    document.temp.submit();
    }
    </script>
    Something like that would work as well, and you could use the same form, and function on all your links.

    ShriekForth

  • #4
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help but it did not work -- I have no clue why? Here is my code. For some reason, it is not passing the variables to the function.

    <html>
    <head>
    <title>Training Wizard</title>
    <link rel="stylesheet" href="/NewPDWeb/proe2primer/Library/primer_style.css" type="text/css">
    <script language='JavaScript'>
    <!--
    function MM_openBrWindow(theURL,winName,features) {
    window.open(theURL,winName,features);
    }


    function subMe(a,b){
    document.wiz.vsSORT = b;
    document.wiz.submit();
    }


    //-->
    </script>
    </head>
    <body bgcolor='#FFFFFF' background='background.gif' bgproperties='' link='#000000' vlink='#000000'><form name="wiz" action="/cgi-tm/prod-def/organize/training_wizard.pl" method="post">
    <a href="javascript:subMe('vsSORT','Status')">Intro to Wildfire</a><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <input type='hidden' name='Username' value='Myname'>
    <input type='hidden' name='Password' value='Mypass'>
    </form></body></html>

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Western US
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This function ...
    Code:
    function subMe(a,b){ 
    document.wiz.vsSORT = b; 
    document.wiz.submit(); 
    }
    is trying to set only 'b', so 'a' will not get set, 'b' will not be set either as there is not field named vsSORT in that form, just username and password. Also, you need to reference the value of the field. Add the second parameter in there as well
    Code:
    function subMe(a,b){ 
        documen.wiz.UserName.value = a
        document.wiz.Password.value = b; 
        document.wiz.submit(); 
    }
    So if you click the link with that function replacing your current one, Username will contain the value 'vsSORT', and Password will contain the value 'Status'.

    ShriekForth


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •