Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:10:52+00:00 2026-06-06T00:10:52+00:00

I’m looking at creating a sweepstake generator and to do this am only using

  • 0

I’m looking at creating a sweepstake generator and to do this am only using HTML and Javascript. I currently have users picking a ‘select’ option for the number of ‘players’ and then an onclick() event which creates that many ‘name’ boxes.

The code for this is:

<label for="playerNumbers">How many people are involved in the sweepstake?</label>
<select id="playerNumbers" name="playerNumbers">
<option value="2" onclick="makeform(2)"> 2 </option>
<option value="3" onclick="makeform(3)"> 3 </option>
<option value="4" onclick="makeform(4)"> 4 </option>
<option value="5" onclick="makeform(5)"> 5 </option>
<option value="6" onclick="makeform(6)"> 6 </option>
<option value="7" onclick="makeform(7)"> 7 </option>
<option value="8" onclick="makeform(8)"> 8 </option>
<option value="9" onclick="makeform(9)"> 9 </option>
<option value="10" onclick="makeform(10)"> 10 </option>
</select>

with the ‘makeform()’ function looking like:

function makeform(numberOfPlayers) {
var x = '<form id="playerNames">';
for (i = 0; i < numberOfPlayers; i++) {
    x += '<label for="player'+(i+1)+'">Player '+(i+1)+'</label>';
    x += '<input type="text" id="player'+(i+1)+'" />';
    x += '<br />';
}
document.getElementById("newForm").innerHTML = x;
}

This works a treat but the problem comes when a user fills in the newly generated form. I included a submit bottom at the bottom of the ‘overall form’ (which includes the new form) but it doesn’t seem to recognize the newly generated form.

I suppose I’m asking two questions:
1.) How do I make this work? Can you infinitely generate forms using Javascript or is there a limit?
2.) Is this the best way to do this? I’m sure it’s not but don’t really know what technology I should be looking at.

Thanks!

(By request – all the code:)

<form id="nameForm">
<div id="teamForm">
<label for="teamNumber">How many teams are involved?</label>
<select id="teamNumber" name="teamNumber">
<option value="2" onclick="makeform1(2)"> 2 </option>
<option value="3" onclick="makeform1(3)"> 3 </option>
<option value="4" onclick="makeform1(4)"> 4 </option>
<option value="5" onclick="makeform1(5)"> 5 </option>
<option value="6" onclick="makeform1(6)"> 6 </option>
<option value="7" onclick="makeform1(7)"> 7 </option>
<option value="8" onclick="makeform1(8)"> 8 </option>
<option value="9" onclick="makeform1(9)"> 9 </option>
<option value="10" onclick="makeform1(10)"> 10 </option>
<option value="11" onclick="makeform1(11)"> 11 </option>
<option value="12" onclick="makeform1(12)"> 12 </option>
<option value="13" onclick="makeform1(13)"> 13 </option>
<option value="14" onclick="makeform1(14)"> 14 </option>
<option value="15" onclick="makeform1(15)"> 15 </option>
<option value="16" onclick="makeform1(16)"> 16 </option>
<option value="17" onclick="makeform1(17)"> 17 </option>
<option value="18" onclick="makeform1(18)"> 18 </option>
<option value="19" onclick="makeform1(19)"> 19 </option>
<option value="20" onclick="makeform1(20)"> 20 </option>
<option value="21" onclick="makeform1(21)"> 21 </option>
<option value="22" onclick="makeform1(22)"> 22 </option>
<option value="23" onclick="makeform1(23)"> 23 </option>
<option value="24" onclick="makeform1(24)"> 24 </option>
<option value="25" onclick="makeform1(25)"> 25 </option>
<option value="26" onclick="makeform1(26)"> 26 </option>
<option value="27" onclick="makeform1(27)"> 27 </option>
<option value="28" onclick="makeform1(28)"> 28 </option>
</select>
<div id="newForm2"></div>
</div>
<label for="playerNumbers">How many people are involved in the sweepstake?</label>
<select id="playerNumbers" name="playerNumbers">
<option value="2" onclick="makeform(2)"> 2 </option>
<option value="3" onclick="makeform(3)"> 3 </option>
<option value="4" onclick="makeform(4)"> 4 </option>
<option value="5" onclick="makeform(5)"> 5 </option>
<option value="6" onclick="makeform(6)"> 6 </option>
<option value="7" onclick="makeform(7)"> 7 </option>
<option value="8" onclick="makeform(8)"> 8 </option>
<option value="9" onclick="makeform(9)"> 9 </option>
<option value="10" onclick="makeform(10)"> 10 </option>
</select>
<div id="newForm"></div>
<input type="submit" value="Submit Form" onclick="doSweepstake(this.form)" />
</form>

and:

function makeform1(numberofTeams) {
var y = '<form id="teamNames">';
for (j = 0; j < numberofTeams; j++) {
    y += '<label for="team'+(j+1)+'">Team '+(j+1)+'</label>';
    y += '<input type="text id="team'+(j+1)+'" />';
    y += '<br />';
}
document.getElementById("newForm2").innerHTML = y;
}

In addition to the function already given above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:10:54+00:00Added an answer on June 6, 2026 at 12:10 am

    This doesn’t work in principle because you can’t nest forms. You’ll need to add the fields to the parent form.

    You could do this with plain JS, but I suggest you don’t reinvent the wheel and learn to use a JS library instead — such as jQuery. This would make your life much easier – it greatly simplifies DOM manipulation (and does much more). For example, you could just do the following:

    $("#playerNumbers option").click(function() {
        var p = $("#playerNames");
        for (var i = 0; i < $(this).attr("value"); i++)
            p.append('<label><input /></label><br />'); // etc
    })
    

    It might look confusing at first, but a second look through this code shows you a lot of familiar things — and the elegance of using something like this instead of the unwieldy beasts that are onclick and innerHTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.