ok here the problem i want to add to values from drop-down menus i got it to work but its is adding as a string not a number
for example i select from the first box the number 2 then i select form the second box the number 3 when i click the button to alert the answer it returns a value of 23 when it should have added the numbers and returned a value of 5
heres the code----- and the link to this live
HTML Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head></head> <body> <script type="text/javascript"> function OnChange2() { var x = document.getElementById('colorsselect').value var y = document.getElementById('colorsselect2').value var var3 = y+x; alert(var3); } </script> <script type="text/javascript"> function bam() { var bed = document.getElementById('bed').selectedIndex; var bedval = document.getElementById('bed')[bed].value; var xxl = document.getElementById('xxl').selectedIndex; var xxlval = document.getElementById('xxl')[xxl].value; var total = bedval+xxlval; alert(total); } </script> <form action=""> <select name='colors1' id='bed'> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <select name='colors2' id='xxl'> <option value="1">1</option> <option value="2">2</option> <option value="3">2</option> <option value="4">4</option> </select> </form> <button type="button" value="My button value" onclick="bam();">button</button> </body> </html>


Reply With Quote

Bookmarks