How to use Javascript in Google sites

Google sites allows you to edit the HTML behind a webpage in Google sites, but if you try to post Javascript into the HTML, Google sites will not allow it. One workaround is to use in-line Javascript. NOTE: another approach to putting custom Javascript into a Google site is to create a custom Google Gadget; see Using custom Google Gadgets to enhance Google sites).

JAVASCRIPT THAT GOOGLE SITES WON'T ALLOW

If you try to post a Javascript function into your Google sites page, like this:

<form name="buyers">

<select name="example3" size=1>

<option selected value = "">Select here</option>

<option value="http://www.lori-v.com/buyers.htm">Buyers Home</option>

<option value="http://www.lori-v.com/closingcosts.htm">Estimated Closing Costs</option>

</select>&nbsp;<input type="button" value="Go!" onClick="gothere3()"> <br>

</form>

<script language="javascript">

<!--

function gothere3(){

var thebox=document.buyers

location=thebox.example3.options[thebox.example3.selectedIndex].value

}

//-->

</script>

Google sites will not allow this. A stand-alone Javascript function is not allowed.

JAVASCRIPT THAT GOOGLE SITES WILL ALLOW

But, if you re-write it to use in-line Javascript, it will work:

<form xmlns="http://www.w3.org/1999/xhtml" name="buyers">

<select name="example3" size="1">

<option selected="" value="">Select here</option>

<option value="http://www.lori-v.com/buyers.htm">Buyers Home</option>

<option value="http://www.lori-v.com/listings.htm">Search For Homes</option>

<option value="http://www.lori-v.com/closingcosts.htm">Estimated Closing Costs</option>

</select>

<input onclick="javascript:window.open(document.buyers.example3.options[document.buyers.example3.selectedIndex].value)" type="button" value="Go!" /> <br />

</form>