jjmusicpro Posted April 15, 2008 Share Posted April 15, 2008 how can i add a value to a hyperlink? i am running ajax, and wanted to pass the value of the hyperlink to ajax... this is what i have now... <a href="" onClick="showHint(this.value)">Click 1</a>[code] [/code] Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 15, 2008 Share Posted April 15, 2008 Anchors cannot have a value. You can use the title attribute instead though. Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted April 15, 2008 Author Share Posted April 15, 2008 i tried this <a href="" onClick="showHint(this.value)" title="Value 1">Value 1</a> but it didnt work this works, if i put it in a drop down box.. <option value="Value 1">Value 1</option> Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 15, 2008 Share Posted April 15, 2008 My knowledge is limited to this subject. But it seems that if you are going to be using title, you should change it from value to title as well. e.g. <a href="" onClick="showHint(this.title)" title="Value 1">Value 1</a> Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted April 15, 2008 Author Share Posted April 15, 2008 Yeah, i just want to be able to pass the value of the hyperlink to my ajax script Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted April 15, 2008 Share Posted April 15, 2008 Yeah, i just want to be able to pass the value of the hyperlink to my ajax script As I said... anchors do not have a "value". The code Zhadus provided you with works. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 15, 2008 Share Posted April 15, 2008 <a href="/url/to/current/script.php?var=1" title="Value 1" onclick="return showHint(this.href);">Value 1</a> with this javascript... function showHint(val) { var urldata = val.slice(val.indexOf('?')); var varvals = urldata.split('='); alert('Value is ' + varvals[1]); return false; } Now you could make this kind of javscript even less invasive by using javascript to add the onclick eventhandler- this is difficult in ie as you would have to faff about for hours simply because someone at Microsoft implemented their addevent fucntionality on a friday afternoon - they got to a point where it actually did something and said 'eureka! - time for the pub' they couldn't be bothered to check if it was useful or not.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.