Matthew Woodard
Matthew Woodard

Reputation: 754

jQuery Change Value based on Value

Can you change the value of an input field based on the original value?

<input type="checkbox" value="fooBar1" class="checkbox" />
<input type="checkbox" value="fooBar2" class="checkbox" />

Was trying something like this ...

if ($('.checkbox').val() == 'fooBar1') {
   $(this).val('1');
}

Upvotes: 0

Views: 90

Answers (2)

user1560022
user1560022

Reputation:

if ($("input.checkbox").attr("value") == "fooBar1") {
   $(this).attr("value","NEW VALUE");
}

Upvotes: 1

Tim Withers
Tim Withers

Reputation: 12059

This will do it:

$(".checkbox[value=fooBar1]").val(1);

Upvotes: 3

Related Questions