javascript - How do I add a value to a list with button click? -


i'm having trouble using appendchild function...

here's code

<!doctype html> <html> <body>  <form oninput="x.value=((parsefloat(winning_number.value)%(parsefloat(total_key_value.value)*100*2))/(parsefloat(total_key_value.value)*2)).tofixed(2)"> <input type="number" id="winning_number" value="" placeholder="winning number"> ~  <input type="number" id="total_key_value" value="" placeholder = "total (keys)"> = <output name="x" for="winning_number total_key_value"></output>% </form>  <button type="submit" onclick="document.getelementbyid("container").appendchild(li);">submit</button>   <ol id="list"></ol>  </body> </html> 

i enter 2 numbers , calculates result using formula.

how can make button add x value list once clicked?

also, want able delete items list if that's possible

im new javascript might realize

thanks

try code https://jsfiddle.net/bfmpkc7p/2/

<form oninput="x.value=((parsefloat(winning_number.value)%(parsefloat(total_key_value.value)*100*2))/(parsefloat(total_key_value.value)*2)).tofixed(2)"> <input type="number" id="winning_number" value="" placeholder="winning number"> ~  <input type="number" id="total_key_value" value="" placeholder = "total (keys)"> = <output id="outputvalue" name="x" for="winning_number total_key_value"></output>% </form> <button id="boton" type="submit">submit</button> <ol id="list"></ol> 

and javascript

$('#boton').click( function() {   value = $("#outputvalue").html();     $('#list').append('<li>'+value+'</li>');  });  $(document).on('click', 'li', function () { $(this).remove(); }); 

when click on button, function create li tag value in output tag id=outputvalue in ol id = list

update!! click on li element , delete. https://jsfiddle.net/bfmpkc7p/3/


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -