Reputation: 378
<input class="y" id="imploding_feature3" type="hidden" name="product_labels_module[3][manual_products]" value=",,,,62,108,,45,">
<input class="y" id="imploding_feature4" type="hidden" name="product_labels_module[4][manual_products]" value=",,,,45,78,,26,">
I would like to get the value inputted from the user and then delete the value. For example, user enter value 45 then it will remove all 45 in textbox but other value will remind ,how can i do it using jquery??
Upvotes: 0
Views: 1784
Reputation: 564
check the output of this demo, I think it does what you want.
Updated script:
$('#removeProduct').on('click', function() {
var input = $('#productId').val();
// loop through each imploding_feature and remove value if exist
$('input[id^="imploding_feature"]').each(function(ndx, elem) {
var values = $(elem).val();
console.log('before =', values);
var valuesarray = values.split(',').map(function(val, ndx) {
return (val === input)?'':val;
}).join(',');
$(elem).val(valuesarray);
console.log('after =', valuesarray);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="productId" value="">
<button id="removeProduct">
remove product id
</button>
<input class="y" id="imploding_feature3" type="hidden" name="product_labels_module[3][manual_products]" value=",,,,62,108,,45,">
<input class="y" id="imploding_feature4" type="hidden" name="product_labels_module[4][manual_products]" value=",,,,45,78,,26,">
Upvotes: 1
Reputation: 406
Assuming u want to keep the values in an array. So let's create an values array to hold the values. Then for each value change of the field we just store the array and empty it
var values=[];
$(document).ready(function(){
//create a value container array
$('#imploding_feature1').change(function(e) {
values.push($(this).val());
$(this).val('');
});
});
Upvotes: 0
Reputation: 1806
Here is my sample:
// assign the value in a variable.
var textValue = $("#inputSample").val();
// this will remove the value in your input element.
$("#inputSample").val("");
the textValue variable has the value of the input element.
Upvotes: 0
Reputation: 401
You don't need jquery to do this. Just use straight JS to set the field value of that element to equal an empty string.
Upvotes: 0
Reputation: 994
$('#imploding_featurel').on('keyup', function(e) {
// enter
if (e.keyCode == 13) {
// get the value
var value = $(this).val()
// empty this
$(this).val('').html('')
}
})
listen to keyup
/keypress
.
Maybe you can add one button to add click
listener.
Upvotes: 0