Help with Object #<Object> has no method 'getElementsById'

Hi guys,
I was playing with some code in my wordpress theme and this javascript is what also calls on php to search my blog. However, Chrome is giving me an Uncaught TypeError: Object #<Object> has no method ‘getElementsById’ and I was hoping someone could help me fix it.
I do not understand why it thinks the method does not exist as I believe it does and I need the elements to be “fetched” by their id.

Does anyone have any suggestions?

Here is my code.

<script type="text/javascript">
			//<![CDATA[
			var searchbox = MGJS.$("searchbox");
			var searchtxt = MGJS.getElementsById("textfield", "input", searchform)[0];
			var searchbtn = MGJS.getElementsById("button", "input", searchform)[0];
			var tiptext = "<?php _e('Search...', 'inove'); ?>";
			if(searchtxt.value == "" || searchtxt.value == tiptext) {
				searchtxt.className += " searchtip";
				searchtxt.value = tiptext;
			}
			searchtxt.onfocus = function(e) {
				if(searchtxt.value == tiptext) {
					searchtxt.value = "";
					searchtxt.className = searchtxt.className.replace(" searchtip", "");
				}
			}
			searchtxt.onblur = function(e) {
				if(searchtxt.value == "") {
					searchtxt.className += " searchtip";
					searchtxt.value = tiptext;
				}
			}
			searchbtn.onclick = function(e) {
				if(searchtxt.value == "" || searchtxt.value == tiptext) {
					return false;
				}
			}
			//]]>
		</script>

I would really appreciate any Feedback or solution.

Thanks in Advance & Best Regards,
Team 1504

I see that many people have viewed this, but not replied.

Currently, I saw that I wrote getElementsbyId
when it should be getElementbyId

However that does not fix the error and it is the same error that shows.
By error, I mean I am getting a js error, but the script is working perfectly.

Is the script running before the elements even exist yet on the page?

no, the script tags are physically right under the html that creates the search

Apparently,MGJS is supposed to implement getElementById. How are you going about that assignment, and how is the object MGJS defined on the page?

Hmm well, this js has to do with a search for a Wordpress Blog, which is part of the theme the client is using for said Blog.

And now that I am reading all the code from the theme’s files that have to do with the search, I do not think MSJS is defined? :blush:

Here is everything that has to do with the search if it helps you guys any to help me or if you may find anything.

<?php if($options['google_cse'] && $options['google_cse_cx']) : ?>
		<form method="get" id="searchform" action="http://www.google.com/cse"> 
			<div>
				<input type="text" id="s" name="s" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}" /> 
				<input type="submit" id="searchsubmit" value="Go" />
				<input type="hidden" name="cx" value="<?php echo $options['google_cse_cx']; ?>" />
				<input type="hidden" name="ie" value="UTF-8" />
			</div> 
		</form>
		<?php else : ?>
		<form id="searchform" action="<?php bloginfo('home'); ?>" method="get">
			<div>
				<input type="text" id="s" name="s" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}">
				<input type="submit" id="searchsubmit" value="Go" />
			</div>
		</form>
		<?php endif; ?>
		<script type="text/javascript">
			//<![CDATA[
			var searchbox = MGJS.$("searchbox");
			var searchtxt = MGJS.getElementById("textfield", "input", searchform)[0];
			var searchbtn = MGJS.getElementById("button", "input", searchform)[0];
			var tiptext = "<?php _e('Search...', 'inove'); ?>";
			if(searchtxt.value == "" || searchtxt.value == tiptext) {
				searchtxt.className += " searchtip";
				searchtxt.value = tiptext;
			}
			searchtxt.onfocus = function(e) {
				if(searchtxt.value == tiptext) {
					searchtxt.value = "";
					searchtxt.className = searchtxt.className.replace(" searchtip", "");
				}
			}
			searchtxt.onblur = function(e) {
				if(searchtxt.value == "") {
					searchtxt.className += " searchtip";
					searchtxt.value = tiptext;
				}
			}
			searchbtn.onclick = function(e) {
				if(searchtxt.value == "" || searchtxt.value == tiptext) {
					return false;
				}
			}
			//]]>
		</script>

I really appreciate your help and I hope you guys can help me fix this :slight_smile:

Regards,
Team 1504