Saturday, October 18, 2008

Billing Form from Class #4

So after reading the HTML DOM tutorial (pretty helpful), re-reading the JavaScript tutorial, and reading the DHTML tutorial, I am much more comfortable in my understanding of JavaScript - I still struggle with knowing how to begin coding, but I can read it comfortably and execute it once I have a little jumpstart. I know that this will still take me a long time to really "get," but I've made strides compared to last week.

At first I looked through all the scripts from the fourth class and tried to meld them together in some weird hybrid (see previous post), but that didn't really work. After a long time, I looked through other people's blogs for some kind of help. Robin W.'s blog really helped me - she had code hints with comments that described each step of the script, so that I at least had some direction. Hopefully, moving forward, I will really be able to do this all on my own.

//get checkbox element using its id
//get billing elements using ids
//get shipping elements using ids
//if checkbox is checked, copy billing info to shipping
//if checkbox is unchecked, remove info from shipping

I didn't get around to:
//Validate Form
//code Submit button

A few things I struggled with:

- Remembering how/when to pass parameters into a function - I kept forgetting to put the checkbox id in the method copyOver() :
  • <input type="checkbox" name="checkme" id="checkme" onclick="copyOver('checkme');" />
- Remembering how variables and method parameters interact:

function copyOver(checkboxElId) {
//get checkbox element using its id
var checkboxEl = document.getElementById(checkboxElId);

later this would become checkboxEl.checked in the if statement

No comments: