faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 12 people (50%) answered Yes
Recently 4 of 9 people (44%) answered Yes

Entry

how do i send a variable via a link, that will be used within the page the link opens

Aug 28th, 2004 10:42
chance drozel, Luiz Paulo Rosa, ben reece, Chance Drozel


Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="Luiz Paulo C. Rosa">
<script language="JavaScript">
<!--
function SymError()
{
  return true;
}
window.onerror = SymError;
//-->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function Lnk()
	{
	document.links[0].href = 'pag2.htm?
var1='+document.frmTeste.txtVar.value;
	}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD=POST name="frmTeste">
<INPUT TYPE="text" NAME="txtVar">
<A HREF="pag2.htm" name="Lnk1" onClick="Lnk()">Link</A>
</FORM>
</BODY>
</HTML>
You can retrieve the value of var1 on pag2.htm using this function:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="Luiz Paulo C. Rosa">
<SCRIPT LANGUAGE="JavaScript">
<!--
var urlHelp = document.location.href;
var strIni = urlHelp.indexOf('var1')+5;
//5 is the length of 'var1'(4)+1 because of the equal sign
var var1 = urlHelp.substr(strIni,urlHelp.length);
document.write('var1= '+var1);
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
----------------------------------
hey i tried that and it didnt work