View Full Version : Submitting a form with a link using javascript

08-19-2002, 09:36 PM
I have many links on my cgi tool that has links like the following:


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

Can I use javascript to do this?

Roy Sinclair
08-19-2002, 09:54 PM
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.

08-19-2002, 10:02 PM
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.

<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">

<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

<a href="javascript:void(0)" onClick="javavscript:setPage('EDIT_TUTORIAL', 'Intro_to_Wildfire', '1')">Intro to Wildfire</a>
function setPage(a,b,c){
document.temp.vsCom = a;
document.temp.Tutorial = b;
document.temp.AllowEdit = c;

Something like that would work as well, and you could use the same form, and function on all your links.


08-20-2002, 12:10 AM
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.

<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) {

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

<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'>

08-20-2002, 05:05 PM
This function ...

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

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

function subMe(a,b){
documen.wiz.UserName.value = a
document.wiz.Password.value = b;

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'.