button.html (1869B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>input type button</title> 4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> 5 <link rel=help href="https://html.spec.whatwg.org/multipage/#button-state-(type=button)"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <form id=f1> 10 <input type=button id=b1 name=b1> 11 </form> 12 <form> 13 <input id=i1 value="foo"> 14 <input type=button id=b2 name=b2> 15 </form> 16 <form> 17 <input type=radio id=i2 checked name=b3> 18 <input type=button id=b3 name=b3> 19 </form> 20 <form> 21 <input type=checkbox id=i3> 22 <input type=button id=b4 name=b4> 23 </form> 24 25 <script> 26 var t = async_test("clicking on button should not submit a form"), 27 b1 = document.getElementById('b1'), 28 b2 = document.getElementById('b2'), 29 b3 = document.getElementById('b3'), 30 b4 = document.getElementById('b4'), 31 i1 = document.getElementById('i1'), 32 i2 = document.getElementById('i2'), 33 i3 = document.getElementById('i3'); 34 35 test(function(){ 36 assert_false(b1.willValidate); 37 }, "the element is barred from constraint validation"); 38 39 document.getElementById('f1').onsubmit = t.step_func(function(e) { 40 e.preventDefault(); 41 assert_unreached("form has been submitted"); 42 }); 43 44 t.step(function() { 45 b1.click(); 46 }); 47 t.done(); 48 49 test(function(){ 50 i1.value = "bar"; 51 b2.click(); 52 assert_equals(i1.value, "bar"); 53 }, "clicking on button should not reset other form fields"); 54 55 test(function(){ 56 assert_true(i2.checked); 57 b3.click(); 58 assert_true(i2.checked); 59 }, "clicking on button should not unchecked radio buttons"); 60 61 test(function(){ 62 assert_false(i3.indeterminate); 63 b4.click(); 64 assert_false(i3.indeterminate); 65 }, "clicking on button should not change its indeterminate IDL attribute"); 66 </script>