javascript onload getelement. onload using javascript to create content no user input comes up when...

8
JavaScript onLoad getElement

Upload: amy-moody

Post on 24-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

JavaScript onLoad getElement

Page 2: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

onload

Page 3: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

onload

Using JavaScript to create content

No user input

Comes up when page LOADS

<body onload=“doitnow();”>

[redo Koozebane; random picture]

Page 4: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

Changes outside forms

Page 5: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

Retrieving the value In JavaScript

document.getElementById("name").value

What does that mean?

document: the web page

getElementById: find this id on the page

Returns an object

Value: get the value of the object

Page 6: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

Writing to the page

Use an id on any element

Replace the element using innerHTML

Allows us to keep the correct semantics in HTML

[Using innerHTML]

Page 7: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

What to Write

Generate HTML that you want.

Concatenate literals and variables.

Example: To build a paragraph using a variable called “content”.document.getElementById(“id”).innerHTML =

‘<p>’+content+’</p>’;

Page 8: JavaScript onLoad getElement. onload Using JavaScript to create content No user input Comes up when page LOADS [redo Koozebane; random picture]

CHANGING HTMLGeneral structure: context.element.attribute

Within form:

formname.element.attribute

form-name.input-id.value

form-name.img-id.src

Outside form:

document.getElementById(“id-name”).attribute

document.getElementById(“id”).innerHTML

document.getElementById(“id”).className

document.getElementById(“id”).src