Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form>
- <input type="text" value="0">
- <input type="text" value="0">
- <select onchange="calcul()">
- <option value="+">+</option>
- <option value="*">*</option>
- </select>
- <div id="rezultate">asdf</div>
- </form>
- <script>
- var op = document.getElementsByTagName('select')[0];
- op.addEventListener('change', calcul);
- function calcul(){
- var vals = document.getElementsByTagName('input');
- var val1 = parseInt(vals[0].value);
- var val2 = parseInt(vals[1].value);
- op = op.options.selectedIndex;
- var result = op===0 ? val1 + val2 : val1 * val2;
- var opr = op===0 ? '+' : '*';
- var resDiv = document.getElementById('rezultate');
- resDiv.innerHTML = val1 + opr + val2 +'='+result;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement