035-form-js.html 1.3 KB

1234567891011121314151617181920212223242526272829
  1. <!doctype html>
  2. <html><head><meta charset="utf-8"><title>035 form JS state</title>
  3. <style>
  4. html,body{margin:0;padding:0;background:#fff;color:#202020;font-family:sans-serif;font-size:13px}
  5. body{padding:10px}h1{font-size:20px;margin:0 0 8px}p{margin:0 0 10px}
  6. input,select{margin-right:8px;font-size:13px}#result{margin-top:12px;padding:8px;background:#ffffcc;color:#000;font-family:monospace;font-weight:bold}
  7. </style></head><body>
  8. <h1>035 &middot; form state from JavaScript</h1>
  9. <p>The script sets value/checked/selectedIndex and reads them back; the result must say PASS.</p>
  10. <form id="f">
  11. <input id="i" type="text" name="q" value="hello">
  12. <input id="c" type="checkbox" name="c">
  13. <select id="s" name="s"><option value="a">One</option><option value="b">Two</option></select>
  14. </form>
  15. <div id="result">checking...</div>
  16. <script>
  17. setTimeout(function () {
  18. var i = document.getElementById('i');
  19. var c = document.getElementById('c');
  20. var s = document.getElementById('s');
  21. i.value = 'world';
  22. c.checked = true;
  23. s.selectedIndex = 1;
  24. var ok = i.value === 'world' && c.checked === true && s.selectedIndex === 1;
  25. document.getElementById('result').textContent = ok ? 'PASS: live form state' :
  26. ('FAIL: i=' + i.value + ' c=' + c.checked + ' s=' + s.selectedIndex);
  27. }, 500);
  28. </script>
  29. </body></html>