SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict mmelen's Avatar
    Join Date
    Jul 2005
    Location
    NJ/NY USA
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    please help me with small textbox javascript issue

    Okay, so I have this: http://www.freeonlinegamefinder.com/test.htm

    Here is what is suppose to happen.
    When you choose "Game Finder" the textbox should say "need gold miner? try..."
    and when you choose "Exact Game" the textbox should say "enter in the exact..."

    It works in IE, but not in Mozilla.

    Another problem,

    I want the text to disappear on blur and reappear back if nothing is entered. it works on the "Game Finder" one, but not the other.

    You can view source on http://www.freeonlinegamefinder.com/test.htm to see the code.

    I really appreciate it if someone can fix this for me!

  2. #2
    SitePoint Member
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Without reading it through more thoroughly right at this moment Mozilla is saying:

    Error: document.getElementById("search") is null
    Source File: ""
    Line: 1

    It says the same to both drop down options. From my first impression I'd just say its because it is written very messily, also I'd like to point out that you should have opening HTML and such tags in there.. really helps

  3. #3
    SitePoint Addict mmelen's Avatar
    Join Date
    Jul 2005
    Location
    NJ/NY USA
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Eudanil View Post
    Without reading it through more thoroughly right at this moment Mozilla is saying:

    Error: document.getElementById("search") is null
    Source File: ""
    Line: 1

    It says the same to both drop down options. From my first impression I'd just say its because it is written very messily, also I'd like to point out that you should have opening HTML and such tags in there.. really helps
    well thats not the page it will be on... I just took it out to show the code to people instead of pasting it here at sitepoint.

  4. #4
    SitePoint Member
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fair enough.

    I'll see if I can find what's causing the error

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    I have moved your scripts to the correct location for maximum readability.
    I have left your code there commented out so you can see the difference.

    It works in all browsers, including Safari... have fun

    HTML Code:
    <html>
    <head>
    <script type="text/javascript" language="javascript">
    function searchfocus()
    	{
    	// if (this.value==this.defaultValue) this.value='';
    	if ((search.value=="need gold miner? search 'gold'")||(search.value=="enter the exact game name"))
    		{
    		search.value='';
    		}
    	}
    	
    function searchblur()
    	{
    	// this.value= (this.value=='') ? this.defaultValue : this.value ;
    
    	if (search.value=='')
    		{
    		var intIndex = D1.selectedIndex ;
    
    		switch (intIndex)
    			{
    			case 0:
    				search.value="need gold miner? search 'gold'" ;
    				break;
    			case 1:
    				search.value="enter the exact game name" ;
    				break;
    			}
    		}
    	}
    
    function changeD1()
    	{
    	// Surprisingly you were correct on this bit..	
    	document.getElementById('search').value=D1.value ;
    	}
    
    </script>
    </head>
    
    <body>
    
    <p>
    <input class="search" onblur="searchblur()" onfocus="searchfocus()" size="30" value="need gold miner? search 'gold'" name="search" id="search"> 
    	<select class="search" onchange="changeD1()" size="1" name="D1" id="D1">
    		<option value="need gold miner? search 'gold'" selected=selected>Game Finder</option>
    		<option value="enter the exact game name">Exact Game</option>
    	</select>
    <input class="play" type="button" value="PLAY!" name="play" id="play" /> 
    </p>
    
    </body>
    </html>

  6. #6
    SitePoint Addict mmelen's Avatar
    Join Date
    Jul 2005
    Location
    NJ/NY USA
    Posts
    243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks so much Eudanil!!!


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
  •