Results 1 to 3 of 3

Thread: Drop Down Menu Need to call <option> values by a string not selectIndex - help

  1. #1
    Join Date
    Dec 2008

    Question Drop Down Menu Need to call <option> values by a string not selectIndex - help


    I have an avatar picker. We have the backend working but it requires that the value of my <option> in a dropdown list has to be a string.

    The purpose of the javascript is to allow the user to preview the avatar before they select it.

    My original preview script uses selectedIndex].value; and assigned a number to each <option>

    Now my value is a string.
    I need to be able to pass a value to a dropdown list that is not a number. The reason is I have to pass a string is for the backend to recoginize the confirm action and update the CMS with the new selection.

    (links to examples are below)

    Here is my the changeAvatar original code that works for previewing the avatars only:

    The Javascript:
    //will be called when the avatar drop list changes
    function changeAvatar(avatarNum) {
    	//get the element that was selected
    	var selectedAvatarNum = $('avatarChange:chooseAvatar')[$('avatarChange:chooseAvatar').selectedIndex].value;
    	var tempAvatar = avatars[selectedAvatarNum];
    	var imgFolders = 'images/themes';
    	//change the porthole image
    	$('portholeAvatar').src = imgFolders + "/" + tempAvatar.porthole_img; //<img id="portholeAvatar">...
    	//change the header image
    	$('headerContainerImage').setStyle({backgroundImage:'url(' + imgFolders + '/' + tempAvatar.banner_img +')'});
    	//change the banner
    	$('avatarImg').src = imgFolders + "/" + tempAvatar.header_img;
    The Html that works for previewing:
    <select id='avatarChange:chooseAvatar' name="avatarChange:chooseAvatar"  onchange="changeAvatar();">	
    <option value="0" >Archon Male</option> 
    	<option value="1" >Archon Female</option> 
    	<option value="2" >Chronox Male</option> 
    	<option value="3" >Chronox Female</option> 
    	<option value="4" >Doron Male</option> 
    	<option value="5">Doron Female</option> 
    	<option value="6">Juror Male</option> 
    	<option value="7">Juror Female</option> 
    	<option value="8">Karakuri Male</option> 
    	<option value="9">Karakuri Female</option> 
    Link to full example that works for previewing avatars only.

    This code works for the CMS but breaks the preview:

    This is new html I have to get to work for the preview side:
    example of full html and code: http://fuzzbert.org/avatar_need2change.html

    <select id='avatarChange:chooseAvatar' name="avatarChange:chooseAvatar"  onchange="changeAvatar();">	
    <option value="arch_m1" >Archon Male</option> 
    	<option value="arch_f1" >Archon Female</option> 
    	<option value="chronox_m1" >Chronox Male</option> 
    	<option value="chronox_f1" >Chronox Female</option> 
    	<option value="doron_m1" >Doron Male</option> 
    	<option value="doron_f1">Doron Female</option> 
    	<option value="juror_m1">Juror Male</option> 
    	<option value="juror_f1">Juror Female</option> 
    	<option value="karakuri_m1">Karakuri Male</option> 
    	<option value="karakuri_f1">Karakuri Female</option> 
    This list is actually render by JSF: <f:selectItem>
    In plain xhtml I could get it to work by add "id" to the <option> like this

    <option value="arch_m_1" >Archon Male</option> 
    	<option value="arch_f_1"  id="0">Archon Female</option> 
    	<option value="chronox_m_1" id="1">Chronox Male</option>
    see example: http://fuzzbert.org/avatar_change.html

    But JSF only allows for an id to be assigned at the <select> Level
    It won't render if id is added to <option>

    I tried to see if itemId would work following JSF convention but is just ignored it. It did not even render it in code of the <option>

    Here is link examples so you can see the full JS and html all together.

    Preview avatar that works selectIndex so see what I need to achieve

    This is format I need to get the preview working again with alternative selectIndex:

    One more note in case it makes a difference:
    The option list is built manually. I can't do it dynamically with JSF's.

    I more of a front-end person and Js is not my strong suit so any advice, recommendation, pointer, examples, or help is greatly appreciated.

  2. #2
    Join Date
    Feb 2008
    Your explanation is too convoluted to straighten out -- but let me say that it makes no difference whether the OPTION value is a string or a number. Meaning, a number is always available for every OPTION whether you specify such a number or not. The selectedIndex is that number. Also meaning, you don't need a number in the OPTION value in order to select an OPTION -- just use the options index for that.

    You can either set selectedIndex directly:
    document.forms['formName'].elements['selectName'].selectedIndex = 2;
    or you can set the associated OPTION's selected property to true:
    document.forms['formName'].elements['selectName'].options[2].selected = true;
    Of course, you can also use a for loop to search the options for the one you wish to select -- if all you have is the string value to identify the OPTION.

  3. #3
    Join Date
    Dec 2008

    Question Thank you!

    Apologies on being convulent. I guess too much information. Thanks for the tips and direction. I will give them a try and see where they go.

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12282 seconds
  • Memory Usage 2,868KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates