views:

169

answers:

2

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 need 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.

+1  A: 

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()

Felix Kling
Thank you sir. This worked straight out of the box when I passed in the correct selectors.
liquilife
A: 

Please try this:

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

HTH

Raja