Hi,

I have this javascript at the top of my php document on my website:

<script type="text/javascript">
document.getElementById('add').addEventListener('click', function(event) {

    event.preventDefault();
    var select = document.getElementById('select').cloneNode(true);
    document.getElementById('form').appendChild(select);

}, false);
</script>

In the body of the php document there is a form :

<form id="form">
    <select id="select">
        <option>one</option><option>two</option><option>three</option>
    </select>
    <button id="add">Add</button>
</form>

For some reason i cant get this code to work. It is meant to add another dropdown list to the document. Are there any errors?

Thanks

The javascript is probably executed before the HTML body is ready. Try putting the javascript code just before the closing body tag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.