javascript - 3 select boxes but one value based off the choices of all 3 -


i making insurance form glasses , first select box insurance plan. second select box style of lens, , third box options want on lens. there way pick 3 insurance plans , choose lens style , pick option , have amount put input box before insurance , input box after insurance. value based off options on last select, different amounts based on plan , lens style?

was thinking of this:

<select> <option>plan a</option> <option>plan b</option> <option>plan c</option> </select>  <select> <option>single vision</option> <option>bifocal</option> <option>trifocal</option> <option>progressive</option> </select>  <select id="options1"> <option>anti-glare coating</option> <option>transitions</option> <option>edge polish</option> <option>sunglass tint</option> </select> <input type="text" id="before1" class="before"> <input type="text" id="after1" class="after"> 

well, if choose "plan a" in drop down, , choose single vision in drop down, options cost:

<select id="options1"> <option value="140,85">anti-glare coating</option> <option value="100,76">transitions</option> <option value="16,9">edge polish</option> <option value="36,15">sunglass tint</option> </select> 

but if chose plan b, progressives, cost same options change becuase of first 2 choices. hope helps clarify. guess looking change value of options on lenses based on first 2 select boxes. :-)

you can create object shows price each option:

var prices = {     'plan a': {         'single vision': {             'anti-glare coating': {                 before: 100,                 after: 50             },             'transitions': {                 before: 80,                 after: 60             },             ...         },         ...     },     ... } 

then after user selects menus, values , use them indexes object:

var plan = document.getelementbyid("plan").value; var type = document.getelementbyid("type").value; var option = document.getelementbyid("options1").value; document.getelementbyid("before1").value = prices[plan][type][option].before; document.getelementbyid("after1").value = prices[plan][type][option].after; 

in real application wouldn't hard-code object that, can database using ajax.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -