Hi,
LaughOutLoud wrote:
Hi. Does anyone knows that how to retrieve variable on a link from
javascript.
e.g., here I have a link
<a href="http://www.domain.com/index.html?id=1 111"
onClick="getid( );">click me</a>
<div id="display"></div>
When I click the link, getid function will retrieve the id value from
the link which is "1111" and display it within <divtag by using
innerHTML. No page refresh.
Is it possible to do that? If so, does anyone know how to do it?
Thanks
Modify getid() to getid( this );
When the method is called, the "A" node is passed to the function, and
you can access its "href" property, which carries the information you
want to display.
"return false;" in the onclick prevents the link to be followed if
JavaScript is enabled (you said you don't want a postback).
<a href="http://www.domain.com/index.html?id=1 111"
onclick="getid( this );return false;">click me</a>
<div id="display">&n bsp;</div>
with
function getid( nLink )
{
if ( nLink
&& nLink.href != null
&& nLink.href.inde xOf( "=" ) -1 )
{
var strId = nLink.href.spli t( "=" )[1];
var nDisplay = document.getEle mentById( "display" );
if ( display )
{
display.firstCh ild.nodeValue = strId;
}
}
}
HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering:
http://www.galasoft-LB.ch
PhotoAlbum:
http://www.galasoft-LB.ch/pictures
Support children in Calcutta:
http://www.calcutta-espoir.ch