...

View Full Version : hyperlink passing parameters when clicked



pinky14
02-17-2012, 05:41 PM
I have two links as shown below. The destination page needs to know which link was clicked in order the render the page accordingly. How could I accomplish that? Can I get some help.

<a href="javascript:func1()" >Historical data 1</a>
<a href="javascript:func2()" >Present data 2</a>

Should I put constant variable in javascript

I tried
<a href="javascript:func1()" id = "1">Historical data 1</a>
<a href="javascript:func2()" id = "2">Present data 2</a>
but how could i write code in destination page to retrieve these values.

Thanks for the help !!!

teedoff
02-17-2012, 05:43 PM
What the code in your functions? Ideally you'd use server side language to pass url variables to the processing page.

<a href="somePage.cfm?somevariable=somevalue">Historical Data 1</a>

pinky14
02-17-2012, 06:10 PM
Thanks for the Reply... But I have to use JavaScript functions in order to go the right destination page. Can I add something in JavaScript or in href to pass another constant variable. I can post my JavaScript code if necessary.

function func1(){
var val = document.form.Year.value;
var si = document.form.Year.selectedIndex;
var textval = document.form.Year.options[si].text;
if(textval > 2010)
{
document.form.action ="Page1.asp";
document.form.method = "post";
document.form.submit();
}
else if (textval < 2011)
{
document.form.action ="page2.asp";
document.form.method = "post";
document.form.submit();
}
}

Similarly func2() is same except else part is directed to page3.asp

teedoff
02-17-2012, 06:13 PM
Thanks for the Reply... But I have to use JavaScript functions in order to go the right destination page. Can I add something in JavaScript or in href to pass another constant variable. I can post my JavaScript code if necessary.

Well no js isn't neccessary to "go to the right page". Is this a homework assignment?

And to note, what happens if a user disables js? then your links dont work at all.

But yes you can post your functions as I mentioned earlier, even thought I guess this woule be a js issue and should probably be in the js forum.

When posting code, use the # button then paste your code between the code tags.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum