SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.
    Code JavaScript:
    <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

  2. #2
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by team1504 View Post
    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?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    no, the script tags are physically right under the html that creates the search

  5. #5
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apparently,MGJS is supposed to implement getElementById. How are you going about that assignment, and how is the object MGJS defined on the page?

  6. #6
    SitePoint Guru team1504's Avatar
    Join Date
    May 2010
    Location
    Okemos, Michigan, USA
    Posts
    732
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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?

    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.
    Code HTML4Strict:
    <?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

    Regards,
    Team 1504


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •