DarkVision
DarkVision

Reputation: 1423

need help appending Javascript onclick

Hi I'm trying to append javascript code when I click a button, but I think I messed up. If someone could help me with syntax. Maybe I'm doing it the wrong way; if someone has a better way to do it, it would be appreciated.

$("#btn_add").click(function(){   
 '<script>$(".selectcategory'+count+'").change(function() {var vv = ($(this).val());$( ".cat'+count+'" ).empty();$(".cat'+count+'").append("<input id="i_index" type="text" name="categorie[]" maxlength="255" style="width:80%" value="vv">");});</script>'
});

Upvotes: 0

Views: 55

Answers (1)

mat
mat

Reputation: 1629

Honostly there is a lot wrong in your code. I am learning Javascript myself at the moment, so maybe i won't provide the solution, but I am trying to help.

First of all, the script tag should be arround your code, not in it. Second use the single and double quotes correct. Last but not least, use some markup in your code. It's hard to see where the issue is.

<script>
$("#btn_add").click(function()
{   
    $(".selectcategory"+count).change(function()
    {
       var vv = ($(this).val());
       $(".cat"+count).empty();
       $(".cat"+count).append('<input id="i_index" type="text" name="categorie[]" maxlength="255" style="width:80%" value="vv">');
    });
});
</script>

Upvotes: 2

Related Questions