javascript if statement syntax (need help) -


i've looked through prior questions not see answer can understand (they more complicated mine).

i'm bootstrapping javascript using old manuals , experiences using scripting language 15 years ago.

by modifying tutorial file have code , works fine

var oemdc1 = parseint(document.getelementbyid("vehicle_oem_draw").value);         var oemdc2 = parseint(document.getelementbyid("vehicle_added_draw").value); var oemdc3 = parseint(document.getelementbyid("new_vehicle_draw").value); var oemdc4 = parseint(document.getelementbyid("include_prism_draw").value); var total_current_draw = document.getelementbyid("total_hourly_current_draw"); total_current_draw.value = oemdc1 + oemdc2 + oemdc3 

but need add code if user clicks radio button (include_prism_draw) different total.

if (oemdc4 == 1) total_current_draw.value = oemdc1 + oemdc2 + oemdc3 + prism_cd; else total_current_draw.value = oemdc1 + oemdc2 + oemdc3; 

but added value (prism_cd) in calculation regardless of radio button values (a "1" or "0"). if neither button clicked still added value.

so think need braces or parentheses or something.

i have var prism_cd declared @ top of doc , inserted results field working in sense.

any appreciated.

(okay, found edit link, should make more prominent).

i cut/pasted code @adam , still prism_cd regardless of state of buttons. (prism_cd number set var , shows accurately when don't want it.)

the button code below. maybe there simple mistake

include prism 1.5 ma current draw in calculation?   <input type="radio" name="include_prism_draw" id="include_prism_draw" value="1" />  yes <input type="radio" name="include_prism_draw" id="include_prism_draw" value="0" /> &nbsp;&nbsp;&nbsp;no 

to answer other question vars, popups user manipulates, script adds values popups , accurately until add yes/no code buttons.

if user wants add prism current draw (prism_cd) click yes , added getting added whenever code in script. @ point not have either button set checked.

the rest of script works accurately can test spreadsheet porting from.

i still have more things work through based on type of "if/else set var" logic once working should go.

i appreciate replies.

m./

i'm not problem is. but, best practice if..else syntax put both blocks in braces.

var oemdc1 = parseint(document.getelementbyid("vehicle_oem_draw").value);         var oemdc2 = parseint(document.getelementbyid("vehicle_added_draw").value); var oemdc3 = parseint(document.getelementbyid("new_vehicle_draw").value); var oemdc4 = parseint(document.getelementbyid("include_prism_draw").value); var total_current_draw = document.getelementbyid("total_hourly_current_draw"); if (oemdc4 === 1){   total_current_draw.value = oemdc1 + oemdc2 + oemdc3 + prism_cd; } else {   total_current_draw.value = oemdc1 + oemdc2 + oemdc3; } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -