I've made a jQuery script, appending/adding to the existing value of an input field. I am doing this by checking if a checkbox is checked, if it is, add text, if it is yet again unchecked, I want to remove that text - not clear the entire value, just remove that little part of the value - I've tried to do this by replacing the added value with nothing, but it doesn't seem to work.
Here is my script;
$(document).ready(
function(){
$('.checkbox').change(function(){
if ($(this).is(':checked')) {
if($('#output').val().indexOf('?') >= 0) {
var input = $( "#output" );
$('#output').val($('#output').val() + '&avatar');
} else {
$('#output').val($('#output').val() + '?avatar');
}
} else {
$('#output').val(value.replace('?avatar', ''));
$('#output').val(value.replace('&avatar', ''));
}
});
});
I am not the best at jQuery here - I only really do it if I have to, so I might just miss the obvious here.
Here's a jsFiddle including my HTML as well.
I've been struggling with this here for a while, any help appreciated - thank you in advance!