0
var TitleVal = encodeURIComponent($("[title='Title Required Field']").val()); // Title has value "car & bus"
//decodeURIComponent(TitleVal); 

var allOptions = document.querySelectorAll("[title='Name'] option"); //Name is other column,

[].some.call(allOptions, function(option) {
        if (option.innerHTML == TitleVal) {
            option.selected = "selected";
            return true;
        }
    }); 

how would I make the symbol in string as normal string?

10
  • I believe looking for decoding the string.
    – Ravindra
    Jan 14, 2016 at 10:52
  • small snippet, what i have understood from your query: var t = 'A & B' var t1 = encodeURIComponent(t) "A%20%26%20B" decodeURIComponent(t1) 'A & B'
    – Ravindra
    Jan 14, 2016 at 10:55
  • in if conditiont the value should come without %20%26 but then it again considers & as symbol n the condition is false
    – KumarV
    Jan 14, 2016 at 11:00
  • In If condition can't you use decodeURIComponent(option.innerHTML) and check. Hope i have understood your problem
    – Ravindra
    Jan 14, 2016 at 11:02
  • Does it helped you
    – Ravindra
    Jan 14, 2016 at 11:27

1 Answer 1

0

A minor change and it worked..

TitleVal =encodeURIComponent($("[title='Title Required Field']").val());

var allOptions = document.querySelectorAll("[title='Name'] option");

[].some.call(allOptions, function(option) {
    if (encodeURIComponent(option.text) == TitleVal) {
        option.selected = "selected";
        return true;
    }
});
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.