CSc 103, Lab 9

November 11, 2019 -- check MY form using JavaScript

For today, please make a copy of my file, wantjavascript.html. You can do this by using File | Save as...
First personalize it by putting your name where it says "(your name here)".
Then add REQUIRED and/or JavaScript to your copy, sufficient to check that all the form elements are filled out appropriately. You may of course use my functions. Put your completed file, still named wantjavascript.html, in your www/ directory on osiris. You do not need a link in your home page.
You may use my functions, or do your own.

You cold also copy the file directly on osiris (using Putty or ssh in terminal window) as follows:
ssh osiris
cp /home/jensen/wantjavascript.html www
Keep the name wantjavascript.html so that I may find it easily!

Then edit the file on osiris , in the ssh session using nano, or however you prefer to edit your files.

Access a cookie in your index.html

If you set a cookie in your php page, for example, with the name of the person filling out your form, please use it this week in your main page, accessing it using javascript, as below.

Please put a link to your form at the bottom of wantjavascript.html  if this is the case


wantjavascript sets the cookie "week11name", onChange to the "Your name" input. (do not change "week11name")

Please access this cookie, using javascript (see using cookies js, -- copy useful script from there. Also example on Osiris, cookie.html) and print it near the top of your index.html. After filling out the form, you should see the name that was typed in the form. If the form hasn't been filled, you won't see anything different on index.html from before.

var cook = cookies_array()
    document.write(cook['week11name'])	//requires my function

	// OR // using regular expression:

    var m = /week11name\=([^\;]+)/i.exec(document.cookie)
    if (m) document.write("Welcome back "+m[1]+"<br>")

There is a link to index.html at the bottom of the form. You can try this even before you put the other javascript with the form.

Algorithm for marking

  1. I try to submit the form
    1. Add one point to score
    2. keep filling things in until it submits
  2. If link to a form is on the page
    1. Go fill it out
  3. Reload your index.html. Do I see my name (from some cookie)?
Document last modified , by Lin Jensen