SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating a function that populates radio buttons

    Hey guys,

    I am looking for some help. I am trying to populate Radio buttons with JavaScript. What I have is two Radio buttons that when the page loads will display a random city next to them. So instead of saying "Desitination1" next the a radio button, it needs to say one of the cities below, and must pull different cities each time the page loads. Any help would be appreciated!

    My cities:
    Code:
    var myVacations = ["Athens", "Madrid", "Tokyo", "Honolulu", "Sydney", "London", "Oslo", "Moscow", "Kingston", "Acapulco", "Brasilia", "Lima", "Chicago", "Toronto", "Cairo", "Egypt", "Capetown"];
    my Radio buttons:

    Code:
    <form name="surveyForm">
        	<fieldset>
                <legend>I would rather vacation in:</legend>
                <label>
    				<input type="radio" name="pollRadio" id="optRadio1" value="" />
    				<span id="optSpan1" ></span>
    			</label>
                <label>
    				<input type="radio" name="pollRadio" id="optRadio2" value="" />
    				<span id="optSpan1"></span>
                </label>
            </fieldset>
        </form>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by prerunninjake View Post
    So instead of saying "Desitination1" next the a radio button, it needs to say one of the cities below, and must pull different cities each time the page loads.
    It's that last bit that's the problem. Do you want each page load to remember the destinations that the previous pages have used, so that it doesn't pick those?
    Or is a random choice from the list of cities good enough for your purpose?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard bronze trophy cydewaze's Avatar
    Join Date
    Jan 2006
    Location
    Merry Land, USA
    Posts
    1,096
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Not to mention that destination1 and destination2 could potentially be the same if it's completely a random choice.
    <cfset myblog = "http://cydewaze.org/">

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by cydewaze View Post
    Not to mention that destination1 and destination2 could potentially be the same if it's completely a random choice.
    That's relatively simple to deal with, by using a random bag to draw them from.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •