Help - Search - Members - Calendar
Full Version: The onload function is not setting value.
HTMLHelp Forums > Programming > Client-side Scripting
Grae
I am having problems with setting a value with onload. Here is an example of the code.

CODE

<form method="get" class="searchform" action=theAction" onload="if('' == '') {document.getElementById('searchinput').value='Type Search Query';} else {document.getElementById('searchinput').value='june';}">
<input class="searchinput" name="s" type="text">
<input class="searchbutton" value="Go" type="submit"></form>


I know you guys might be thinking that the if condition is hard coded, and the if will never change. In the real code, php changes the first value of the if's condition.

I think the above code should always set the value 'Type Search Query', in the box. However, it does not set any value.

Can someone please explain what is going on? Also, is there another, btter way to do something like this a different way?

Thanks,
Grae
pandy

So what does PHP change ('' == '') to? Have you cheched that it really changes?
Christian J
The onload event doesn't apply to form elements. You might use it with BODY, or you could run the javascript without the onload as long as the script appears after all affected HTML elements.

But I don't see the point of using javascript in this case. Why can't PHP print the INPUT value?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.