0

I have following jquery script

var $checked = $inputs.filter(':checked');
var numChecked = $checked.length;

$checked.each(function () {
    var val = (this).value;

    if (val.indexOf("Ya") != -1) {
        alert('old val   ' + val);
        val = val.replace("Ya", "Y2a");
        alert('new val   ' + val);
        alert($(':input[value^="' + val + '"]').value);

        //$(val).attr({ 'disabled': true, 'aria-disabled': true })[flag ? 'addClass' : 'removeClass']('ui-state-disabled');
    }
}); 

the old value is : ltrYaxis0

the new value is : ltrY2axis0

I am able to replace but when I am trying to test whether its finding the new input or not, its saying undefined. I have to make this hidden or disable

2
  • can you show us the html of the element you're trying to match? Commented Sep 16, 2013 at 5:20
  • You want to find input with "Ya" value, replace it's value and find it? Commented Sep 16, 2013 at 6:58

3 Answers 3

1
+50

Trye this

 val = val.replace("Ya", "Y2a");
       $(':input[value='+val + ']'.attr({ 'disabled': true, 'aria-disabled': true })
Sign up to request clarification or add additional context in comments.

Comments

0

If I understood the requirement correctly, this will do

var $checked = $inputs.filter(':checked');
var numChecked = $checked.length;

$checked.filter(function () {
    return this.value.indexOf("Ya") != -1;
}).val(function (idx, val) {
    return val.replace("Ya", "Y2a");
}).attr({
    'disabled': true,
    'aria-disabled': true
})[flag ? 'addClass' : 'removeClass']('ui-state-disabled');

3 Comments

what do you mean by jquery failed to load
please just tell me how to find the element with dynamic value
look at the first part of the script $checked.filter(function () { return this.value.indexOf("Ya") != -1; })
0

This line

var val = (this).value;

has 2 errors.

  • You missed the $
  • and not .value but .val()

    var val = $(this).val();
    

and be careful :

    $(val).attr({ 'disabled': true, 'aria-disabled': true })

it shoul be

$(this).attr({ 'disabled': true, 'aria-disabled': true }) ...

Comments

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.