I have a requirement to compare text input value to data attribute value.
I select text field value from jquery auto complete selection option and I set attribute at that time as follows
select: function (event, ui) {
var terms = $(this).attr('dt-value') ? $(this).attr('dt-value') + ',' + ui.item.value.replace(',', '|,') : ui.item.value.replace(',', '|,');
this.value = terms.replace(/\|,/g, ',');
$(this).attr('dt-value', terms);
return false;
}
But in edit option if user deletes value using backspace attribute will not updated.
dt-value="NMC|, ltd,Coromandal|, LLC"
But in text field value shows without | symbol. I want to update the attribute with current value in text field if user remove one value.
Kindly help
Related
I have an ID input box, I want to mask first 4 digits of that field but when I submit I still need to submit with the real data.
Currently what I'm doing is:
maskInputVal($input) {
// Mask client id first 4 numbers with XXXX eg. XXXX4323 (real data is 23434323)
let currentInputValue = $input.val();
if (currentInputValue && currentInputValue.length > 4) {
input.val(currentInputValue.replace(/^.{4}/g, 'XXXX'));
}
}
But in this way the real value is changed. So when I submit it won't submit with 23434323 but XXXX4323.
How can I just change the view value via JQuery?
Before masking the value, keep the value in some hidden field. Then use the value from the hidden field for processing.
maskInputVal($input) {
// Mask client id first 4 numbers with XXXX eg. XXXX4323 (real data is 23434323)
let currentInputValue = $input.val();
$("#some_hidden_field").val(currentInputValue);
if (currentInputValue && currentInputValue.length > 4) {
input.val(currentInputValue.replace(/^.{4}/g, 'XXXX'));
}
}
I have a form where i need to auto calculate value for checked row.
http://codepen.io/anon/pen/dOBaNN?editors=1010
I am calculating the value for the text field on keyup function but need to do following
Keep All text fields disabled
Second i need to enable only text field related to the checkbox checked
Third Calculate sum for only Checked text field
Right now i am able to calculate value for all checkbox not sure how to map checked checbox to related input and calculate values accordingly.
tried few thing but it keep breaking
1) Too disable your text fields set the disabled property to true.
$(".auto-sum").each(function () {
$(this).prop('disabled', true);
});
2) Enable inputs with checkboxes
$('input[type=checkbox]').on('change', function() {
var id = $(this).val();
var active = $(this).prop('checked');
$('.auto-sum[name=Amount' + id + ']').attr('disabled', !active);
calculateSum();
});
3) Skip disabled inputs when calculating
$(".auto-sum").each(function () {
if ($(this).prop('disabled')) return;
[...]
});
I updated your codepen: http://codepen.io/anon/pen/VmJgxM?editors=1011
I have multiple select inputs on a page and I'd like to set all of them to have a particular option selected if a checkbox is checked
Once the form is submitted the inputs that have been updated will be looped through and sent to the database, so I have a function to append a string to the option value which is called on change of the select
This is all working great, however I'd like to append the updated string (to the value, not text) when the select option is changed by the checkbox being checked, but can't seem to get this to work
Fiddle https://jsfiddle.net/69zzr6xa/2/
I've tried looping through each select like so and then checking if the second option is already selected. If not, append the string, but it doesn't appear to work
$('select').each(function() {
if (!$(this).$('option').text == 'Two') {
var inputname = $(this).find(":selected")[0].value;
$(this).(":selected").val(inputname + "-updated");
}
});
I think this is what you are looking for.
function set_to_two() {
$('option:nth-child(2)').each(function(){
$(this).prop('selected', true);
if( $(this).val().indexOf('-updated') < 0 ){
$(this).val( $(this).val() + "-updated" );
}
});
set_updated();
}
I have a ASP website in which I have a repeater, which has a combo box and textbox.I need to have a text box value converted to uppercase when i select
particular value from combo box, but not for all values from combo box .I have tried onChange event and onKeypress Event also in javascript,but could not able
to breakthrough.
function changecase(combobOxClientId,textboxClientId)
{
var combo=$find(combobOxClientId);
if(combo.get_value()=='Textvalue')
{
var textbox=$find(textboxClientId).value;
some code here........ `}`
You need to it like this.
function changecase(combobOxClientId, textboxClientId) {
if ($("#" + combobOxClientId).val() == 'Textvalue') {
var txtval = $("#" + textboxClientId).val();
$("#" + textboxClientId).val(txtval.toUpperCase());
}
}
Assumption : combobOxClientId, textboxClientId are actual ID of elements existing in page.
each checkbox that i check, i fill the input with it's id
now, how can i retrieve this id that i put inside the input if the user uncheck the checkbox?
exp:
estate SC,SP was checked;
input recieve SC,SP value in this format = SC,SP
but the user uncheck the checkbox with SC value, then SC should be removed from the input.
this is what i'm doing to fill the input with the checkboxes.
var separador = ",";
var estadosS = "";
$(".checkboxEstados").live("click", function(){
if($(this).is(":checked")){
estadosS += (estadosS == "") ? "" : separador;
estadosS += $(this).attr("id");
$("#holdEstados").val(estadosS);
}else{
// now i'm just cleaning all the input,
// but i need to clean only the checkbox that was unchecked
$("#holdEstados").val("");
}
});
dont know if i was clear, any question, be my guest.
Thanks.
An easy way to solve this is to avoid parsing and removing parts of the data. Instead of trying to remove 'SC', instead regenerate the entire contents of the text field each time any checkbox is selected.
When a checkbox click event is detected, deleted the contents of the text input field, scan all of the selected checkboxes, and include their IDs in the text input field.
You're logic can be greatly simplified. Simply grab each checkbox that is checked when the click event fires:
$(".checkboxEstados").live("click", function() {
var aryIds = new Array();
$(".checkboxEstados:checked").each(function() {
aryIds.push($(this).attr("id"));
});
$("#holdEstados").val(aryIds.toString());
});
Here's a working fiddle.
I would store the value in an array and add and remove values from it and then write the array to the output instead of trying to parse the text each time:
var estadosS = [];
$(".checkboxEstados").live("click", function(){
var index;
if($(this).is(":checked")){
// append the id to the list
estadosS.push($(this).attr("id"));
}else{
index = estadosS.indexOf($(this).attr("id"));
if(index > -1) {
estadosS.splice(index, 1);
}
}
$("#holdEstados").val(estadosS.join(separador));
});
If all you are aiming to do is get a list of the checked values from all the check boxes, you could do:
$('.checkboxEstados:checked').each(function(){
alert($(this).val());
});
And that should return all the check box items that have been checked. Then you don't have to worry about adding and removing data from a text box. I'm just alerting the value, you would want to store them into an object or something more useful.