Tuesday, March 10, 2009

class 4 | in-class assignment: intro to JavaScript with a form


I was happy to finally get the text copying over in all three fields during class Saturday. I skipped over the styling. It took some time for me to figure out exactly what I was trying to accomplish with the JavaScript, another few minutes trying to get the code from the Image Swap example to somehow work (no dice), and more time to finally start looking for a way to get/set the value property of the form fields. Searching google for .document textarea helped me find a way to copy over the text.


I ended up with three very specific functions (pointing to longwinded id/name/form tags), that I think can be reduced to one. I wanted to make sure I had everything working properly at first. This script doesn't really capture the text and then put it somewhere else, instead it just sets the value of the right side equals to the left side onkeyup.

After going through the other JavaScript examples on the blog over the next couple of days, I should be able to think of alternate ways to do this.

2 comments:

  1. Hi Geoff,
    In your code, you are getting the value of the left fields by using syntax like this:
    document.left_form_name.username_left_name.value

    This is the "old fashioned" way of doing things. What I'd like you to use is something like this instead:
    document.getElementById("username_left_id").value

    Do that for all the places you are trying to get or set the value of a form field.

    You will see that all my examples use this document.getElementById() function to access the properties of elements on the page.

    ReplyDelete
  2. Appreciate the clarification, Amos. WIll definitely update this using the document.getElementById() function and use it from now on.

    ReplyDelete