0

I know how to create a button in HTML but how would I create a JavaScript function that when the button is pressed it keeps creating multiple buttons and just keeps adding them to the screen?

   <script>
    function repeats() {
            ?
    }
   </script
   <input id ="addsubmit"  type="submit" value= "Submit" style = "margin-top: 25px;">
   </input>
1
  • 2
    It doesn't look like you've tried anything yet. Please do so, or if you have, show us what you've tried. Otherwise it looks like you're asking for free code. Commented Oct 22, 2012 at 0:34

1 Answer 1

1

Here you go - please let me know is this what you asked for :-)

<html>
<head>
<script language="javascript">
    function repeats() {
        document.getElementById('buttons').innerHTML += '<input id ="addsubmit" onclick="repeats()";  type="submit" value= "Submit" style = "margin-top: 25px;">';
    }
</script>
</head>

<body>
 <input id ="addsubmit" onclick="repeats()";  type="submit" value= "Submit" style = "margin-top: 25px;">
     </input>
     <div  id="buttons">buttons here: </div>
</body>
</html>
Sign up to request clarification or add additional context in comments.

2 Comments

@salihOvicX Yea that works, what does the innerHTML mean in the function?
@HomerHomer The inner HTML of the tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.