0

I got a problem with my Script. Its working great with a "normal" name for the Selection, but I use a Shop CMS which names the Selection like this: "ItemOrderParams[0][g19]" and the script isnt working anymore with that name. Can somebody solve this problem? I have no Idea how to fix it.

$("input[id=steckdose]").on("change", function(){
    if($(this).is(":not(:checked)"))
      $(function() {
          $('[name=ItemOrderParams[0][g19]]').val( '3' );
      })
});

$("input[id=steckdose]").on("change", function(){
    if($(this).is(":checked"))
      $(function() {
        $('[name=ItemOrderParams[0][g19]]').val( '2' );
      })
});

--

<select name="ItemOrderParams[0][g19]">
  <option value="1">Red</option>
  <option value="2" selected="1">Green</option>
  <option value="3">Blue</option>
</select>
Ahmad
  • 12,336
  • 6
  • 48
  • 88
Numenx
  • 3
  • 2

2 Answers2

0

You must use quotes when an attribute value contains special characters (like [ & ])

$("input[id=steckdose]").on("change", function(){
    if($(this).is(":not(:checked)"))
        $(function() {
            $('[name="ItemOrderParams[0][g19]"]').val( '3' );
    })
});
$("input[id=steckdose]").on("change", function(){
    if($(this).is(":checked"))
        $(function() {
            $('[name="ItemOrderParams[0][g19]"]').val( '2' );
    })
});
Jason
  • 54
  • 4
0

Escape the brackets

$('[name=ItemOrderParams\\[0\\]\\[g19\\]]')
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • Thanks for the fast answer, i gave rep to Jason since hes new and had none but your answer is great too, i use your solution.Anyway much thanks :) – Numenx Dec 30 '14 at 15:22