Results 1 to 3 of 3

Thread: Getting images to appear via radio buttons in a cookie

  1. #1
    Join Date
    Dec 2008

    Exclamation Getting images to appear via radio buttons in a cookie

    I'm stuck on the last assignment for my Javascript class:


    Basically, I am building a band name generator that shows a genre picked via radio buttons. I can't get the images or genre to appear via my getValue function, which seems to always show up as undefined. Any help would be greatly appreciated!

    Here's parts of the code:

    var whichGenre = document.myForm.genre.value;
    function getValue(whatGenre) {
    whichGenre = whatGenre;
    }//end of getValue function

    function process(){
    var theName = document.myForm.firstName.value;
    var myNumber = document.myForm.number.value;
    var nouns = document.myForm.s.value;
    var gen = whichGenre;
    var genImg = whichGenre+".jpg";

    var cookieElements = theName + "***" + myNumber + "***" + nouns + "***" + gen + "***" + genImg + "***";
    //the escape method takes what cookieElements is holding and encodes it into ASCII code.
    document.cookie = escape(cookieElements) +"; expires=" + ["Thursday, 01 Jan 2009 08:00:00 GMT"];

    window.location = "getCookieInfo.htm";
    }//end of process function

    <span>Choose your band's sound:</span>
    <span id="bandID" style="display: none;">Text</span><br>
    <span class="radioOptions">
    <input name="genre" value="Metal" onClick="getValue(this.id)" onChange="bandCheck()" type="radio">Heavy<br />
    <input name="genre" value="Punk" onClick="getValue(this.id)" onChange="bandCheck()" type="radio">Edgy<br />
    <input name="genre" value="Emo" onClick="getValue(this.id)" onChange="bandCheck()" type="radio">Emotional<br />
    <input name="genre" value="Indie" onClick="getValue(this.id)" onChange="bandCheck()" type="radio">Original<br />
    <input name="genre" value="Pop" onClick="getValue(this.id)" onChange="bandCheck()" type="radio">Popular<br /><br />
    <input value="Generate Band Name" onClick="checkForm()" type="button">

  2. #2
    Join Date
    Dec 2005


    Running you link for "Assignment #5" I get this error
    Error: invalid XML attribute value
    Source File: http://student5www.fullcoll.edu/0078...54/a4ChanL.htm
    Line: 2, Column: 12
    Source Code:
    <span align=

  3. #3
    Join Date
    May 2007
    The reason you are getting undefined is because you are sending into the getValue function this.id, and this does not have an id?? So you should do this;

    function getValue(genre) {
    whichGenre = genre.value;
    }//end of getValue function
    and in the onclicks you should have this:

    <input name="genre" value="Metal" onclick="getValue(this)" onChange="bandCheck()" type="radio">Heavy<br />

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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