html - JavaScript alert -
html - JavaScript alert -
i have problem homework... don't know what's wrong code.. homework create simple learning mathematic level selection... utilize drop downwards menu choosing level , arithmetic operations... problem when click button go function start() save level , operation been chosen 2 variable levelselect , operationselect...and test alert(levelselect); ...supposed show alert window level select...but can't work... view post , willing help me...thanks... ><
class="snippet-code-js lang-js prettyprint-override"><script language="javascript"> var levelselect; var operationselect; var num1; var num2; function start() { levelselect = form.element["form1"]["level"].value; operationselect = form.element["form1"]["operation"].value; alert(levelselect); } </script>
class="snippet-code-html lang-html prettyprint-override"><html> <head> <title>untitled document</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> </head> <body> <form id="form1" name="form1" method="post" action=""> <table align="center"> <tr align="center"><td><label>choose level :</label> <select id="level" > <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> </td> </tr> <tr align="center"><br><br><br><td><label>choose arithmetic operations :</label> <select id="operation" > <option value="add">addition</option> <option value="sub">subtraction</option> <option value="div">division</option> <option value="mul">multiplication</option> </select> </td> </tr> <tr> <td align="center"><input type="button" onclick="start()" value="generate question"/></td> </tr> </table> </form> </body> </html>
if want utilize form javascript variable, should alter input type , remove function invocation:
<input type="submit" value="generate question" />
then change:
<form id="form1" name="form1" method="post" action="" onsubmit="start(this);return false;">
in way function invoked on click of input but, passing so:
function start(myform) { levelselect = myform["level"]value; operationselect = myform["operation"]value; alert(levelselect); }
in function "start" have variable: myform can used select 2 select values
http://jsfiddle.net/l64d5nle/1/
javascript html
Comments
Post a Comment