1

I have some hidden input values that I would like to have be changed to a certain value once a user clicks on a link.

Dom
  • 38,906
  • 12
  • 52
  • 81
EverywhereSean
  • 35
  • 1
  • 1
  • 4
  • Why do you want to require a hidden input? – Sharlike Jan 21 '13 at 17:09
  • not sure what you mean by "choose a value for not selected" - not selected in your example is a link/list element, not a form field. – Marc B Jan 21 '13 at 17:09
  • can you please try to explain you need better ? give some time to rewrite your problem in a way to be clear. remember you need to help us understand that we can help you solve your problem – Abu Romaïssae Jan 21 '13 at 17:14
  • You should be able to change an element's attributes whether hidden or not. What problem are you encountering? – isherwood Jan 21 '13 at 17:59

3 Answers3

5
$('.someLink').click(function(){
    $('.someHiddenInput').val('new value');
});

I think this is what you mean.

HTML would look something like:

<a href="#" class="someLink">click me to change value</a>
<input type="hidden" name="hiddenVal" class="someHiddenInput" value="old value" />
Marcus Recck
  • 5,075
  • 2
  • 16
  • 26
2
<input type="hidden" id="txtTextHdn" name="txtTextHdn" value="Y" />
<a href="#" id="testLink">Click Me!</a>

$("#testLink").click(function () {
    alert($("#txtTextHdn").val());
    $("#txtTextHdn").val('X');
    alert($("#txtTextHdn").val());
})

This should work.

Melu
  • 1,835
  • 3
  • 14
  • 13
0

Do something like this:

JAVASCRIPT:

$(*link selector*).click(function(){
    $(*hidden selector*).val();
});

Here is a demo: http://jsfiddle.net/UbScn/

Dom
  • 38,906
  • 12
  • 52
  • 81