Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 3.33 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2008, 05:04 AM   PM User | #1
techie35
New to the CF scene

 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
techie35 is an unknown quantity at this point
Question Prototype: How to switch from drop down list to Radio buttons with variables as Value

HI,

I have working code a friend did for me that creates an array and builds a select option (drop down list). Based on the option choosen in the drop list three images change. This basically picking a theme for you page:
An Avatar, header image and background image.

The option select works but I want change the drop list to radio buttons.
How would I change the ChangeAvatar function (pasted below) to recognize input from a radio button and update when the radio's button selection changed?


Any help very appreciated!!!

The javascript is using the prototype framework. Links and posted code snippet below.

Here are links to sample pages:
Working dropdown list:
http://fuzzbert.org/change_test.html

This is the sample set up I would like but does not work:
http://fuzzbert.org/change_test_radio.html

The part that call the drop down list is here:

//will be called when the avatar drop list changes
function changeAvatar(avatarNum) {

//get the element that was selected
var selectedAvatarNum = $('avatarDropList')[$('avatarDropList').selectedIndex].value;

var tempAvatar = avatars[selectedAvatarNum];
var imgFolders = 'images/themes';
//change the porthole image
$('portholeAvatar').src = imgFolders + "/" + tempAvatar.porthole_img; //<img id="portholeAvatar">...
//console.debug($('portholeAvatar').src);
//change the header image
$('headerContainerImage').setStyle({backgroundImage:'url(' + imgFolders + '/' + tempAvatar.banner_img +')'});

//change the banner
$('avatarImg').src = imgFolders + "/" + tempAvatar.header_img;

console.debug($('avatarImg').src);
}


//will be run automatically when page loads. it builds the select/option drop list under the porthole.
function populateAvatarDropList() {

//loop through avatar array of objects
for(var i = 0; i< avatars.length; i++) {
//create <option> tag
var tempOption = document.createElement("option");
tempOption.value = i; //set <option value=???> ??? is the current avatar number from array
tempOption.innerHTML = avatars[i].name + " (" + avatars[i].gender + ")"; //display name and gender of avatar within <option>???</option> tag

$('avatarDropList').appendChild(tempOption); //command to put <option> tag into <select> list

}

//auto select chronox female, array number of chronox female is 2
$('avatarDropList').options[2].selected =true;
}


//the onload event
window.onload = function() {
populateAvatarDropList();
}

//on change event listener for avatar drop list. will run changeAvatar function above
//Event.observe($('avatarDropList'), 'change', changeAvatar);
techie35 is offline   Reply With Quote
Reply

Bookmarks

Tags
drop down, dynamic forms, javascript, prototype, radio buttons

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:52 PM.


Advertisement
Log in to turn off these ads.