locked
Html 5 pass html encode value as dropdown selected value RRS feed

  • Question

  • User-893002196 posted

    Hi,

    I have html 5 with Jquery setting up the dropdown selected value as

    var ProcessorVal = "@Model.Processor" == "" ? "NA" : decodeEntities("@Model.Processor");         
                $('select[name="Processor"] option[value=' + ProcessorVal+']').attr("selected", "selected");

    However, I getting error:-

    Unhandled exception at line 2, column 31040 in https://localhost:44395/node_modules/jquery/dist/jquery.min.js
    0x800a139e - JavaScript runtime error: Syntax error, unrecognized expression: select[name="Processor"] option[value=Intel® Core™ i3-6100H Processor]

    My function encoder.js as https://www.strictly-software.com/scripts/downloads/encoder.js

    Please advise.

    Thank you.

    Regards,

    Micheale

    Monday, January 7, 2019 10:27 AM

Answers

  • User-893002196 posted

    Hi,

    Sorry. Managed to spot out my issue. Just missing " " around value=

    Solution:

    $('select[name="Processor"] option[value="' + ProcessorVal+'"]').attr("selected", "selected");

    Thanks.

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 7, 2019 10:32 AM