Arman Saparbekov
Arman Saparbekov

Reputation: 39

How to set/change input value on other div click?

How to set/change input value on other div click? Input type is hidden. It is possible?

Upvotes: 0

Views: 1202

Answers (5)

thecodeparadox
thecodeparadox

Reputation: 87073

$('#your_div').on('click', function() {
  $('#hidden_input').val('some_val');
});

Here your_div points to id of your div and hidden_input is the id of hidden field. You use can any valid jQuery selectors for them.

Upvotes: 5

Kasyx
Kasyx

Reputation: 3200

Its no, problem:

$(document).ready(function() {
    $('#div').click( function() {
        $('#input').val('value');
    });
});

Remember, you can work on hidden or display: none elements like they are visible.

Upvotes: 0

Tats_innit
Tats_innit

Reputation: 34107

Working demo http://jsfiddle.net/aqrvA/5/ OR http://jsfiddle.net/aqrvA/1/

API: http://api.jquery.com/val/

Hope this helps

code

$("#iron").click(function() {
    alert("Before Change ==> " + $("#hulk").val());
    $("#hulk").val("IRONMAN");

    alert("After Change ==> " + $("#hulk").val());
});​

Upvotes: 0

mithilatw
mithilatw

Reputation: 908

$('#div_to_click').click(function(){
  $('#hidden_input').val('input_value');
});

Hope it helps :-)

Upvotes: 0

Talha
Talha

Reputation: 19252

$("#target").click(function() {
  $('#hiddedID').val('Some Value');
});

Upvotes: 1

Related Questions