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?

7 of 8 people (88%) answered Yes
Recently 5 of 6 people (83%) answered Yes

Entry

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

Jun 3rd, 2002 09:38
Luiz Paulo Rosa, ben reece,


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