0

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');
}

2 Answers 2

3

This will do it:

$(".checkbox[value=fooBar1]").val(1);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Worked like a charm, forgot you could use the value attribute as the selector.
1
if ($("input.checkbox").attr("value") == "fooBar1") {
   $(this).attr("value","NEW VALUE");
}

2 Comments

This worked for me, but trying to do this same thing to more than one element ... like so, jsfiddle.net/8g9vP/5
I stripped down some stuff to make it simpler, idk what exactly you wanted to do but here's what i got: jsfiddle.net/8g9vP/7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.