How to pass the jquery variable into the input as a attribute [duplicate]











up vote
2
down vote

favorite













This question already has an answer here:




  • How to use javascript variables in jquery selectors

    6 answers




How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?



var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);









share|improve this question















marked as duplicate by Mohammad, Community Nov 19 at 9:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    $("input[type=radio][name="+name+"]").attr('disabled', true);
    – Ramin
    Nov 19 at 9:24






  • 1




    $(`input[type=radio][name=${name}]`).attr('disabled', true);
    – fanjabi
    Nov 19 at 9:26

















up vote
2
down vote

favorite













This question already has an answer here:




  • How to use javascript variables in jquery selectors

    6 answers




How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?



var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);









share|improve this question















marked as duplicate by Mohammad, Community Nov 19 at 9:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    $("input[type=radio][name="+name+"]").attr('disabled', true);
    – Ramin
    Nov 19 at 9:24






  • 1




    $(`input[type=radio][name=${name}]`).attr('disabled', true);
    – fanjabi
    Nov 19 at 9:26















up vote
2
down vote

favorite









up vote
2
down vote

favorite












This question already has an answer here:




  • How to use javascript variables in jquery selectors

    6 answers




How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?



var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);









share|improve this question
















This question already has an answer here:




  • How to use javascript variables in jquery selectors

    6 answers




How to add the Jquery or Javascript variable into the input attribute. Whether it is possible or not?



var name="Jack";
$("input[type=radio][name=name]").attr('disabled', true);




This question already has an answer here:




  • How to use javascript variables in jquery selectors

    6 answers








javascript jquery input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 9:41









jnuK

1,4651325




1,4651325










asked Nov 19 at 9:20









Gowtham Koushik

617




617




marked as duplicate by Mohammad, Community Nov 19 at 9:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Mohammad, Community Nov 19 at 9:25


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    $("input[type=radio][name="+name+"]").attr('disabled', true);
    – Ramin
    Nov 19 at 9:24






  • 1




    $(`input[type=radio][name=${name}]`).attr('disabled', true);
    – fanjabi
    Nov 19 at 9:26
















  • 1




    $("input[type=radio][name="+name+"]").attr('disabled', true);
    – Ramin
    Nov 19 at 9:24






  • 1




    $(`input[type=radio][name=${name}]`).attr('disabled', true);
    – fanjabi
    Nov 19 at 9:26










1




1




$("input[type=radio][name="+name+"]").attr('disabled', true);
– Ramin
Nov 19 at 9:24




$("input[type=radio][name="+name+"]").attr('disabled', true);
– Ramin
Nov 19 at 9:24




1




1




$(`input[type=radio][name=${name}]`).attr('disabled', true);
– fanjabi
Nov 19 at 9:26






$(`input[type=radio][name=${name}]`).attr('disabled', true);
– fanjabi
Nov 19 at 9:26














2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Try this



var name="Jack";
$("input[type=radio][name="+name+"]").attr('disabled', true);





share|improve this answer




























    up vote
    0
    down vote













    You have to use quotes around your attribute selector value. Further, name=name does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):






    const name = "foo"
    console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

    <input type="radio" name="foo" />

    <input type="radio" name="bar" />








    share|improve this answer




























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      Try this



      var name="Jack";
      $("input[type=radio][name="+name+"]").attr('disabled', true);





      share|improve this answer

























        up vote
        1
        down vote



        accepted










        Try this



        var name="Jack";
        $("input[type=radio][name="+name+"]").attr('disabled', true);





        share|improve this answer























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Try this



          var name="Jack";
          $("input[type=radio][name="+name+"]").attr('disabled', true);





          share|improve this answer












          Try this



          var name="Jack";
          $("input[type=radio][name="+name+"]").attr('disabled', true);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 9:22









          Kamil Kiełczewski

          8,00775486




          8,00775486
























              up vote
              0
              down vote













              You have to use quotes around your attribute selector value. Further, name=name does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):






              const name = "foo"
              console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

              <input type="radio" name="foo" />

              <input type="radio" name="bar" />








              share|improve this answer

























                up vote
                0
                down vote













                You have to use quotes around your attribute selector value. Further, name=name does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):






                const name = "foo"
                console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

                <input type="radio" name="foo" />

                <input type="radio" name="bar" />








                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You have to use quotes around your attribute selector value. Further, name=name does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):






                  const name = "foo"
                  console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

                  <input type="radio" name="foo" />

                  <input type="radio" name="bar" />








                  share|improve this answer












                  You have to use quotes around your attribute selector value. Further, name=name does not "insert" the variable's value as you intend to. You can use backticks (template literals) to do so. The following example only selects the input with name="foo" (jQuery $ does the same):






                  const name = "foo"
                  console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

                  <input type="radio" name="foo" />

                  <input type="radio" name="bar" />








                  const name = "foo"
                  console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

                  <input type="radio" name="foo" />

                  <input type="radio" name="bar" />





                  const name = "foo"
                  console.log(document.querySelector(`input[type="radio"][name="${name}"]`))

                  <input type="radio" name="foo" />

                  <input type="radio" name="bar" />






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 9:25









                  lipp

                  2,5381818




                  2,5381818















                      Popular posts from this blog

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin