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