开发者

Populate hidden form element value on title from clicked anchor tag via Jquery

Hey all. I'm trying to set a value on a hidden form element based on a link that is clicked. I figure the best way to go about this is to pass along the anchor title attribute as the value for a particular hidden form element. This hidden form element value will n开发者_C百科eed to be updated depending on the latest link that is clicked. I've scoured google for jQuery snippets to achieve this but can't seem to find a good starting point to run with this.

Any help is appreciated! I'm learning, learning.


Without any HTML, it is just guessing, but a general approach would be:

$('a').click(function(e) {
     e.preventDefault(); // <-- don't follow the link
     $('#id-of-hidden-field').val($(this).attr('title'));        
});

This binds a click handler to any link (of course you should restrict this set somehow) and puts their the title attribute into a hidden field (that is referenced by an ID).

Reference: click(), val(), attr(), preventDefault()


Please try this:

$("a").click(function(){$("#hdnField").val($(this).attr("title");return false;});

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜