Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2012, 04:11 AM   PM User | #1
jordan2000
New to the CF scene

 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jordan2000 is an unknown quantity at this point
passing variables in href tag

What is the correct syntax for passing variables in a href tag when the href is outside of the javascript tags? I believe it is not recognizing the href because it is not reading the variables: boxid & projectname. Please advise.

*******************************************************


<script type="text/javascript" language="javascript">

var linkURL = '';
var boxid = '';
var changeLinkURL = '';


function getUrlVars()
{
var vars = [], boxid;
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

function PassQueryString()
{
boxid = getUrlVars()["boxid"];
projectName = getUrlVars()["project"];
alert("ParseQueryString - BoxID :" + boxid);
alert("ParseQueryString - ProjectName :" + projectName);

}
function changeLinkURL()
{
boxid = getUrlVars()["boxid"];
projectName = getUrlVars()["project"];
linkURL = "C:\Users\Geri\Desktop\test_1.htm + "?boxid=" + boxid + "&projectName=" + projectName";
}
function Project(pname)
{
location.href=menuURL[pname];
}


</script>


<script type="text/javascript">
var first = getUrlVars()["boxid"];
var second = getUrlVars()["project"];
alert("back button : " + "" + first);
alert("back button : " + "" + second);
</script>



<a href="C:\Users\Geri\Desktop\test_1.htm?boxid=DBB&amp;project=projectName">


<IMG style="BORDER-BOTTOM: 0px solid;
BORDER-LEFT: 0px solid; BORDER-TOP: 0px solid; BORDER-RIGHT: 0px solid" border=0
alt="Back Button" src="C:\Users\Geri\Desktop\test_1.htm/Back%20Button/back_button1.gif">
</A></P>

</a>

<body>
</body>
</html>

Last edited by jordan2000; 08-08-2012 at 04:22 AM..
jordan2000 is offline   Reply With Quote
Old 08-08-2012, 05:19 AM   PM User | #2
Scriptr
Regular Coder

 
Join Date: Oct 2011
Posts: 106
Thanks: 12
Thanked 0 Times in 0 Posts
Scriptr is an unknown quantity at this point
The first problem I see is with the URL itself. I have not had much luck getting Windows-style directories to work well in a browser. Try replacing C:\Users\Geri\Desktop\test_1.htm with file:///Users/Geri/Desktop/test_1.htm*

Second, I notice your quotations are not matched:

linkURL = "C:\Users\Geri\Desktop\test_1.htm + "?boxid=" + boxid + "&projectName=" + projectName"; should be

linkURL = "C:\Users\Geri\Desktop\test_1.htm" + "?boxid=" + boxid + "&projectName=" + projectName"; **

And back to the link itself, you shouldn't use an entity for the "&"

Hope I could help .
The "getUrlVars()" method you use here would have been helpful to me on my first project, where I had a password protected page (the password was less for actual protection; as my father always says, "locks only keep honest people out"). I ended up needing to set up a localhost server.... backstory over...


*it might be file:///c/....
**You could actually cut that part out, making it linkURL = "C:\Users\Geri\Desktop\test_1.htm?boxid=" + boxid + "&projectName=" + projectName";

Last edited by Scriptr; 08-08-2012 at 06:01 PM..
Scriptr is offline   Reply With Quote
Old 08-09-2012, 12:35 PM   PM User | #3
Minisuit
New to the CF scene

 
Join Date: Aug 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Minisuit is an unknown quantity at this point
passing variables in href tag

We can pass variable using the ? Symbol.
for example :

is we want to send a name and id of a person the we can sent it using the following format.

name = "Minisuit";
Id= 1001;
Now we can send it

<a href =nextpage.html?FirstName=name&id=id >click Me </a>

Best Regards,
Navin Patel

Last edited by VIPStephan; 08-09-2012 at 02:00 PM.. Reason: removed fake signature
Minisuit is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.