www.webdeveloper.com
Results 1 to 2 of 2

Thread: 2 Drop down lists in table - not working!

  1. #1
    Join Date
    Jan 2011
    Posts
    2

    2 Drop down lists in table - not working!

    Hi,

    I've got some great code from here and it will be perfect for my site with some changes.

    The page is going to be a bike builder where people can choose multiple options and get a quote which updates itself. A second form will allow people to compare 2 bikes.

    They need to be in 2 seperate cells so that they can sit next to each other with tables describing what's in the dropdown.

    I can't get the 2nd form. I've added a second javascript and changed the var but I still can get it to work.

    If someone can spot my error or see a better way of doing it that I will be extremely grateful.

    Many, many thanks in advance.

    [HTML
    <html>
    <head>
    <title>Drop-down</title>
    <script language="JavaScript" type="text/javascript">

    function calc(){
    var totalStr = '|Frameset|Groupset|Wheels|Saddle|Handlebars|Tyres|Finishing Kit|Pedals|Powermeter\n'; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var i=1; i<=9; i++) {
    DDL = document.getElementById('dropDownList'+i);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[0].total.value=totalValue;
    if (cnt == 9) { alert(totalStr); } // for testing purposes
    }
    </script>
    <script language="JavaScript" type="text/javascript">
    function calc1(){
    var total1Str = '|Frameset|Groupset|Wheels|Saddle|Handlebars|Tyres|Finishing Kit|Pedals|Powermeter\n'; // for testing only
    var total1Value=0;
    var DDL1;
    var cnt1 = 0; // for testing only
    for (var j=10; j<=18; j++) {
    DDL1 = document.getElementById('dropDownList'+j);
    temp = DDL1.options[DDL1.selectedIndex].value;
    total1Value += Number(temp);
    if (DDL1.selectedIndex != 0) { total1Str += '|'+temp; cnt1++; } // cnt1++ is for testing only
    }
    document.forms[0].total.value=totallValue;
    if (cnt1 == 18) { alert(total1Str); } // for testing purposes
    }
    </script>
    <style type="text/css">
    .style1 {
    font-family: Tahoma;
    font-size: small;
    }
    .style2 {
    font-size: x-small;
    }
    .style3 {
    font-family: Tahoma;
    font-size: x-small;
    }
    </style>
    </head>
    <body>
    <table cellpadding="0" cellspacing="0" style="width: 100%">
    <tr>
    <td style="width: 90" valign="top">
    <table cellpadding="0" cellspacing="0" class="style1" style="width: 100%; height: 294px">
    <tr>
    <td>
    <table style="width: 100%">
    <tr>
    <td class="style2" style="height: 28" valign="top">Frame</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Groupset</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Wheels</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Saddle</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Handle Bars</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">Tyres</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Pedals</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Fininshing Kit</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Powermeter</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    <td>
    <table>
    <form id="dropDownForm" name="dropDownForm">
    <tr><td>
    &nbsp;<select id="dropDownList1" onChange="calc();" name="D1" style="width: 232px" >
    <option value="1000" selected="">TF100 Alloy</option>
    <option value="1200">TF300C Carbon</option>
    <option value="1300">TF400C Carbon</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList2" onChange="calc();" name="D2">
    <option value="1000" selected="">Miche</option>
    <option value="313.00">Miche 10sp +100</option>


    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList3" onChange="calc();" name="D3">
    <option value="200" selected="">Miche</option>
    <option value="100">Standard </option>

    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList4" onChange="calc();" name="D4">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">Standard RED LED</option>

    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList5" onChange="calc();" name="D5">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">Standard </option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList6" onChange="calc();" name="D6">
    <option value="200" selected="">Miche9sp</option>
    <option value="100">ABC</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList7" onChange="calc();" name="D7">
    <option value="200" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Stand</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList8" onChange="calc();" name="D8">
    <option value="200" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td>
    &nbsp;<select id="dropDownList9" onChange="calc();" name="D9">
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td valign="top">
    <span class="style3">Total Value&nbsp; </span>&nbsp;<input readonly onFocus="blur()" type="text" size="4" name="total" value="1000" style="width: 46px">
    </td></tr>
    </form>
    </table>
    </td>
    <td>
    <table cellpadding="0" cellspacing="0" class="style1" style="width: 100%; height: 294px">
    <tr>
    <td>
    <table style="width: 100%">
    <tr>
    <td class="style2" style="height: 28" valign="top">Frame</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Groupset</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Wheels</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Saddle</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Handle Bars</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">Tyres</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Pedals</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Fininshing Kit</td>
    </tr>
    <tr>
    <td class="style2" style="height: 28" valign="top">
    Powermeter</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    <td>
    <table>
    <form id="dropDownForm1" name="dropDownForm1">
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList10" onChange="calc1();" style="width: 231px" >
    <option value="100" selected="">TF100</option>
    <option value="120">TF300C</option>

    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList11" onChange="calc1();" >
    <option value="100" selected="">Miche9sp</option>
    <option value="313.00">Miche10sp +100</option>

    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList12" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList13" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList14" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList15" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList16" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList17" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td style="width: 236px">
    &nbsp;<select id="dropDownList18" onChange="calc1();" >
    <option value="1000" selected="">Miche/Campagnolo 9sp</option>
    <option value="100">Standard RED LED</option>
    </select>
    </td></tr>
    <tr><td valign="top" style="width: 236px">
    <span class="style3">Total Value&nbsp; </span>&nbsp;<input readonly onFocus="blur()" type="text" size="4" name="total" value="1000" style="width: 46px">
    </td></tr>
    </form>
    </table>

    </td>
    </tr>

    </html>
    [/HTML]

  2. #2
    Join Date
    Jan 2011
    Posts
    2
    Problem found in red below:

    <script language="JavaScript" type="text/javascript">

    function calc2(){
    var totalStr = ''; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var j=1; j<=9; j++) {
    DDL = document.getElementById('dropDownList'+j);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[0].total.value=totalValue;
    }
    </script>
    <script language="JavaScript" type="text/javascript">

    function calc3(){
    var totalStr = ''; // for testing only
    var totalValue=0;
    var DDL;
    var cnt = 0; // for testing only
    for (var j=10; j<=18; j++) {
    DDL = document.getElementById('dropDownList'+j);
    temp = DDL.options[DDL.selectedIndex].value;
    totalValue += Number(temp);
    if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
    }
    document.forms[1].total.value=totalValue;
    }
    </script>


    It had nothing to do with naming variables differently!

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.14008 seconds
  • Memory Usage 2,873KB
  • Queries Executed 15 (?)
More Information
Template Usage (32):
  • (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
  • (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