From jacobson@math-cs.cns.uni.edu Wed Jun 19 10:39:38 2002 Date: Wed, 19 Jun 2002 10:33:04 -0500 (CDT) From: Mark Jacobson To: 810-088-06@uni.edu Subject: cookie12.html modifications Hi 088 students, The URL http://www.cns.uni.edu/~jacobson/js/cookie12.html is a modification of the cookie1.html web page, as discussed in class today. Here is the new code: i = 0; while ( !document.f1.elements[i].checked ) i++; document.bgColor = document.f1.elements[i].value; These 3 lines of code replace this cookie1.html code. (Note: You have cookie1.html as a handout from today's class). if (document.f1.elements[0].checked) { c = 0; } else if (document.f1.elements[1].checked) { c = 1; } else if (document.f1.elements[2].checked) { c = 2; } else if (document.f1.elements[3].checked) { c = 3; } else if (document.f1.elements[4].checked) { c = 4; } else if (document.f1.elements[5].checked) { c = 5; } else if (document.f1.elements[6].checked) { c = 6; } else if (document.f1.elements[7].checked) { c = 7; } document.bgColor = document.f1.elements[c].value; The 9 lines of code are replaced by using a while loop to iterate the variable i over the radio buttons until the one that is checked is discovered. There is one other change in the cookie12.html version of cookie1.html. It now accepts m, M, f, or F for gender, by adding the single statement: gender = gender.toLowerCase(); if (!document.cookie) { n = window.prompt('Enter your name','name?'); do { gender = window.prompt('What is your gender? ' + 'male or female - use m or f', 'M or F'); gender = gender.toLowerCase(); } while (gender != "m" && gender != "f"); document.cookie = "Name=" + n + "&" + "Gender=" + gender; } Hands-on class tommorrow (Thursday), in Wright 112 lab. Assignment2 will be ready on the web page later today, probably by early this afternoon. It will not be due until next Tuesday. Mark