mardi 20 novembre 2018

Javascript using innerHTML and If function to double values

  1. Include this content:

a. A textbox with id 'number'

b. A select list with id 'double'. Options and values are DOUBLE, NO THANKS

c. A submit button with id 'go'. The surface of the button will show 'GO'.

d. A with id 'result'

e. tag to link in a JavaScipt library with any name you want.

B. Create javascript 03.js with an event handler for when the object 'go' is clicked:

  1. The handler will:

a. Get values from number and double. Ensure the value from number is numeric.

b. If the value from double equals 'DOUBLE' then multiply the value from number by 2

c. Set innerHTML of 'result' to the value from number. Do this whether the value was doubled or not.

So far I have

 <body>
 <input id = 'number' name = '' value = '' class = ''>
 <select id = 'double' name = 'DOUBLE'>
 <option value = 'DOUBLE'>DOUBLE</option>
 <option value = 'NO THANKS'>NO THANKS</option>
 </select>
 <button id = 'go' class = ''>GO</button>
 <span id = 'result'></span>

 <script src = 'js/javascript 03.js'></script>

 document.getElementById('go').onclick = function () {

 var data1 = document.getElementById('number'). value;

 data1 = parseFloat(number);

 var data2 = document.getElementById('double').value;


 if (document.getElementById('double').value == 'DOUBLE') {

 var total = (var data1* 2);

 };

 document.getElementById('result').innerHTML =' 
 <b>document.getElementById('number'). value</b>';



 };

Aucun commentaire:

Enregistrer un commentaire