0

I'm trying to write a simple javascript function that will clone some html input fields when the user clicks a button, but for some reason the button's click function isn't being called when I click it. Any ideas why?

Here's the javascript:

<SCRIPT LANGUAGE="JavaScript">
$(document).ready(
    function(){

        $("#default-label").hide();
        $("#default-element").hide();

        var counter = parseInt($("#counter").val());

        $("#addProduct").click(
            function(){

                var product = $('#fieldset-default');
                var newProduct = product.clone(true);
                newProduct.insertAfter(product);
                    document.getElementById("addProduct").innerHTML = 'Add More';
                    $("#counter").val(++counter);
            }
         );
    }
);
</script>

My HTML for the button:

<button id="addProduct" type="button" name="add">Add Product</button>
5
  • 4
    <SCRIPT LANGUAGE="JavaScript">? What is this, 1999? It should be <script type="text/javascript"> or in HTML5, just <script>. Commented Dec 29, 2011 at 19:05
  • 2
    Seems to work jsfiddle.net/3AzHQ Commented Dec 29, 2011 at 19:07
  • 1
    Forgot to include jquery. My brain must still be on christmas vacation. thanks. Commented Dec 29, 2011 at 19:08
  • It works fine: jsfiddle.net/LLRcP Your problem is elsewhere. Commented Dec 29, 2011 at 19:08
  • Seems to work for me: jsfiddle.net/5YRum Commented Dec 29, 2011 at 19:09

1 Answer 1

2

i think you missed jquery plugin,included latest version of jquery library, if not there.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.