www.webdeveloper.com
Results 1 to 2 of 2

Thread: Object trouble

  1. #1
    Join Date
    Feb 2012
    Posts
    1

    Object trouble

    Dear friends,

    I do not know what is wrong with the following function. It simply does not work

    function getValues(com)

    {

    alert("entered");

    var obj = {};

    obj.0.code='1';

    obj.0.name='Anand';

    obj.0.email='777';

    obj.0.phone='999';

    obj.0.mobile='0';

    obj.1.code='2';

    obj.1.name='Ravi';

    obj.1.email='null';

    obj.1.phone='2';

    obj.1.mobile='2';

    obj.2.code='3';

    obj.2.name='hjhjh';

    obj.2.email='null';

    obj.2.phone='0';

    obj.2.mobile='6';

    obj.3.code='6';

    obj.3.name='Anand1';

    obj.3.email=' dfdd';

    obj.3.phone='32';

    obj.3.mobile='333';

    obj.4.code='7';

    obj.4.name='Anand888';

    obj.4.email=' dfdfdfd';

    obj.4.phone='9999999999';

    obj.4.mobile='9999999999';

    obj.5.code='8';

    obj.5.name='Parul ';

    obj.5.email='anandshrivastava1203@gmail.com';

    obj.5.phone='4032448';

    obj.5.mobile='0';

    obj.6.code='9';

    obj.6.name='XYZ';

    obj.6.email='London';

    obj.6.phone='0';

    obj.6.mobile='0';

    obj.7.code='10';

    obj.7.name='XYZ';

    obj.7.email='America';

    obj.7.phone='0';

    obj.7.mobile='0';

    obj.8.code='11';

    obj.8.name='Anand jjjjj';

    obj.8.email='7';

    obj.8.phone='7';

    obj.8.mobile='7';

    obj.9.code='12';

    obj.9.name='Anand';

    obj.9.email='trial';

    obj.9.phone='343';

    obj.9.mobile='33';

    obj.10.code='13';

    obj.10.name='Anand';

    obj.10.email='lokesh';

    obj.10.phone='22';

    obj.10.mobile='22';

    obj.11.code='14';

    obj.11.name='Anand';

    obj.11.email='mit';

    obj.11.phone='6';

    obj.11.mobile='6';

    obj.12.code='15';

    obj.12.name='Jaya Bachhan';

    obj.12.email='jya';

    obj.12.phone='55';

    obj.12.mobile='55';

    obj.13.code='17';

    obj.13.name='Employee';

    obj.13.email='33343';

    obj.13.phone='3333';

    obj.13.mobile='3333';

    obj.14.code='18';

    obj.14.name='High Court';

    obj.14.email='dfdfd';

    obj.14.phone='77';

    obj.14.mobile='77';

    obj.15.code='19';

    obj.15.name='Ajeeb Data';

    obj.15.email='mail@gmail.com';

    obj.15.phone='7614032448';

    obj.15.mobile='9329549284';

    obj.16.code='20';

    obj.16.name='New item';

    obj.16.email='x@y.com';

    obj.16.phone='33';

    obj.16.mobile='44';

    obj.17.code='21';

    obj.17.name='Newest';

    obj.17.email='dddd';

    obj.17.phone='0';

    obj.17.mobile='0';

    obj.18.code='22';

    obj.18.name='Ultimate';

    obj.18.email='dddd';

    obj.18.phone='0';

    obj.18.mobile='0';

    obj.19.code='23';

    obj.19.name='Pen';

    obj.19.email='dfd';

    obj.19.phone='2';

    obj.19.mobile='2';

    obj.20.code='24';

    obj.20.name='Pencil';

    obj.20.email='fd';

    obj.20.phone='0';

    obj.20.mobile='0';

    obj.21.code='25';

    obj.21.name='klk';

    obj.21.email='ff';

    obj.21.phone='0';

    obj.21.mobile='0';

    obj.22.code='26';

    obj.22.name='Godrej';

    obj.22.email='fdfd';

    obj.22.phone='323';

    obj.22.mobile='323';

    obj.23.code='27';

    obj.23.name='adsda';

    obj.23.email='a@c.com';

    obj.23.phone='11';

    obj.23.mobile='11';

    obj.24.code='28';

    obj.24.name='Today';

    obj.24.email='a@c.com';

    obj.24.phone='111';

    obj.24.mobile='111';

    obj.25.code='29';

    obj.25.name='adsd';

    obj.25.email='a@c.com';

    obj.25.phone='11';

    obj.25.mobile='11';

    obj.26.code='30';

    obj.26.name='Now';

    obj.26.email='a@c.com';

    obj.26.phone='11';

    obj.26.mobile='11';

    obj.27.code='31';

    obj.27.name='Immediaate';

    obj.27.email='a@b.c';

    obj.27.phone='22';

    obj.27.mobile='22';

    obj.28.code='32';

    obj.28.name='Today';

    obj.28.email='a@c.com';

    obj.28.phone='11';

    obj.28.mobile='11';

    obj.29.code='33';

    obj.29.name='adsd';

    obj.29.email='a@c.com';

    obj.29.phone='11';

    obj.29.mobile='11';

    obj.30.code='34';

    obj.30.name='ssssss';

    obj.30.email='a@c.com';

    obj.30.phone='111';

    obj.30.mobile='121';

    obj.31.code='35';

    obj.31.name='perfet';

    obj.31.email='a@c.com';

    obj.31.phone='12';

    obj.31.mobile='12';

    obj.32.code='36';

    obj.32.name='perfet';

    obj.32.email='a@c.com';

    obj.32.phone='12';

    obj.32.mobile='12';

    obj.33.code='37';

    obj.33.name='this is ';

    obj.33.email='a@c.com';

    obj.33.phone='11';

    obj.33.mobile='11';

    obj.34.code='38';

    obj.34.name='adsd';

    obj.34.email='a@c.com';

    obj.34.phone='11';

    obj.34.mobile='11';

    obj.35.code='39';

    obj.35.name='Anand';

    obj.35.email='anand@gmail.com';

    obj.35.phone='4032448';

    obj.35.mobile='939549284';

    obj.36.code='40';

    obj.36.name='Ajax';

    obj.36.email='anand@gmail.com';

    obj.36.phone='44';

    obj.36.mobile='44';

    obj.37.code='41';

    obj.37.name='as';

    obj.37.email='abc@abc.com';

    obj.37.phone='12';

    obj.37.mobile='12';

    obj.38.code='45';

    obj.38.name='all new';

    obj.38.email='shanky.jbp@gmail.com';

    obj.38.phone='11';

    obj.38.mobile='11';

    obj.39.code='46';

    obj.39.name='no new';

    obj.39.email='shanky.jbp@gmail.com';

    obj.39.phone='11';

    obj.39.mobile='11';

    obj.40.code='47';

    obj.40.name='hifi technique';

    obj.40.email='shanky.jbp@gmail.com';

    obj.40.phone='22';

    obj.40.mobile='22';

    obj.41.code='48';

    obj.41.name='ooops';

    obj.41.email='shanky.jbp@gmail.com';

    obj.41.phone='3434';

    obj.41.mobile='3434';

    obj.42.code='49';

    obj.42.name='wifi';

    obj.42.email='a@c.com';

    obj.42.phone='4032448';

    obj.42.mobile='4032448';

    obj.43.code='50';

    obj.43.name='New today';

    obj.43.email='shanky.jbp@gmail.com';

    obj.43.phone='12';

    obj.43.mobile='12';

    obj.44.code='51';

    obj.44.name='dddd';

    obj.44.email='shanky.jbp@gmail.com';

    obj.44.phone='12';

    obj.44.mobile='22';

    obj.45.code='52';

    obj.45.name='Feb';

    obj.45.email='shanky.jbp@gmail.com';

    obj.45.phone='3232';

    obj.45.mobile='2323';





    var value=com.options[com.selectedIndex].value;

    alert(value);

    alert(obj.value);

    if (obj[value])

    {

    alert("entered");



    document.getElementById["phone"].value=obj.value.phone;

    document.getElementById["email"].value=obj.value.email;

    document.getElementById["mobile"].value=obj.value.mobile;

    }

    }



    However, when i comment out all the objs the function starts working.
    Please help, where I am wrong.

    Anand.

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    You cannot use dot notation on an object member that starts with a number.
    Instead set and retrieve values like they are arrays:

    Code:
    obj[13].phone = '3333';
    ... or if the number is follower by alpha characters ...
    Code:
    obj['13abc'].phone = '3333';
    As it looks like you are simply attaching groups of fields onto an object in sequential order, you could also use an array[] and populate it with objects{}:

    Code:
    var obj = [
    	{
    		code   : '1',
    		name   : 'Anand',
    		email  : '777',
    		phone  : '999',
    		mobile : '0'
    	},
    	{
    		code   : '2',
    		name   : 'Ravi',
    		email  : 'null',
    		phone  : '2',
    		mobile : '2'
    	}
    ];
    
    alert(obj[0].name); //Anand
    alert(obj[1].code); //2
    Last edited by bionoid; 02-21-2012 at 01:37 PM.
    JavaScript: Learn | Validate | Compact | bionoid

Thread Information

Users Browsing this Thread

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

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.34200 seconds
  • Memory Usage 2,857KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (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
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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 (70):
  • 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_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