Testing for page elements

To test for a form

The following function tests to see if a form is loaded before working within the form.

function TargetLoaded(obj)
{
var stat = (obj !=null)
// determine status, if the form is loaded and not equal to null
if (!stat)
{
alert("The form is not loaded, please wait a moment and try again.");
return stat
} // end of conditional
} // end of TargetLoaded()
function writeToForm()
{ var autoform = document.forms[0]
if (TargetLoaded(autoform))
{ // Code to work form here.
} // of conditional
}// end of writeToForm()

Square Bracket Notation

Syntax for referencing a form element contained in an iframe from the parent document

setting a value

window.frames['iframe name'].document.forms[0].elements[array id].value = somevariable;
someothervar = window.frames['iframe name'].document.forms[0].elements[array id].value ;
window.frames['iframe name'].document.forms[z]['control Name'].value =datavalu[i];

String Manipulation

To change the Case of variable strings

var thistext = alltext.value;
thistext = thistext.toUpperCase()
thattext = thattext.toLowerCase()

toString()

toString() creates a string from elements of an array separated by commas.

contact = new Array("Peter","George","Matt");
alert(contact.toString()); //would return Peter,George,Matt

Substring methods

var substring_name = string_name.substr(start_position, substring_length);
var substring_name = string_name.substring(start_position, end_position);

Using Javascript to add HTML code to a web page

innerHTML

function enterHTML(passed)
{
var targt = passed; //value passed is the DIV id 'targetloc'
var initial = document.getElementById(targt) ;
initial.innerHTML = "<P>New Form <\/P> \n <FORM> <INPUT TYPE = 'button'" + " VALUE = 'Test Me'" +'onClick = "alert' + "('it works')"+ '"'+ "> <\/FORM>";
var textresult =initial.innerText;
}

Click to demonstrate the innerHTML function.


This text to be replaced by a form with a button.


Escaped Characters.

Syntax ___ Character Comment
\n new line Makes the resulting code more readable
\r carriage return
\' single quote
\" quotation marks
\/ back slash Used in closing an html element </p> would be <\/p>
Hosted by www.Geocities.ws

1