Here's the code I'm to refer to:
[HTML]
<html>
<body>
....
<form method="get" action="http://www.google.com/search" name="google" />
<input type="text" name="q" size="25" maxlength="255" value="- search this site -" onclick="ClearI fAppropriate(); " class="textbox" />
<a onclick="submit ();" href="#">Search </a>
</form>
...
</html>[/HTML]
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript" language="JavaScript" >
- <!--
- var LabelText = "- search this site -";
- if(document.google.q.value.length == 0) {
- document.google.q.value = LabelText;
- }
- function ClearIfAppropriate() {
- if(document.google.q.value == LabelText) {
- document.google.q.value = "";
- }
- }
- //-->
- </script>
* if I embed the code BEFORE the function call, e.g. in the <head> zone where it would normally belong, the code runs properly but FF generates a javascript error 'document.googl e has no properties' and directs me to the line if(document.goo gle.q.value.len gth == 0) of the js code.
* if I put the code in a separate file with <script src="...> anywhere on the page, be it in the header zone or after the function call where I previously embedded the code, the function fails when clicking on the text box (which calls the function) and I get a js error 'ClearIfAppropr iate is not defined' which directs me to the first line of the html code <!DOCTYPE ....
Now I've linked to code before and had no problems, in fact <a onclick="submit ();" href="#"> refers to a function in a linked file
Expand|Select|Wrap|Line Numbers
- function submit() {
- document.google.submit();
- }
Would appreciate any help you can offer.
Thanks!
Greg