save_restore_radio_groups.sjs (1303B)
1 var pages = [ 2 "<!DOCTYPE html>" + 3 "<html><body>" + 4 "<form>" + 5 "<input name='a' type='radio' checked><input name='a' type='radio'><input name='a' type='radio'>" + 6 "</form>" + 7 "</body></html>", 8 "<!DOCTYPE html>" + 9 "<html><body>" + 10 "<form>" + 11 "<input name='a' type='radio'><input name='a' type='radio' checked><input name='a' type='radio'>" + 12 "</form>" + 13 "</body></html>", 14 ]; 15 16 /** 17 * This SJS is going to send the same page the two first times it will be called 18 * and another page the two following times. After that, the response will have 19 * no content. 20 * The use case is to have two iframes using this SJS and both being reloaded 21 * once. 22 */ 23 24 function handleRequest(request, response) { 25 var counter = +getState("counter"); // convert to number; +"" === 0 26 27 response.setStatusLine(request.httpVersion, 200, "Ok"); 28 response.setHeader("Content-Type", "text/html"); 29 response.setHeader("Cache-Control", "no-cache"); 30 31 switch (counter) { 32 case 0: 33 case 1: 34 response.write(pages[0]); 35 break; 36 case 2: 37 case 3: 38 response.write(pages[1]); 39 break; 40 } 41 42 // When we finish the test case we need to reset the counter 43 if (counter == 3) { 44 setState("counter", "0"); 45 } else { 46 setState("counter", "" + ++counter); 47 } 48 }