www.webdeveloper.com
Results 1 to 2 of 2

Thread: A little help with function.

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Red face A little help with function.

    Hi have made/making a function that checks if the the box has anything written in.
    If something is entered a the word TICK comes up on the side.

    Here is the function:
    Code:
    <script>
    function checkInput(div_name) {
    if (this.value != '') {
    document.getElementById(div_name).style.display ='inline'; 
    } else {
    document.getElementById(div_name).style.display ='none'; 	
    }
    }
    </script>
    And here is the html:
    Code:
    <table>
    <tr>
        <td width="200">First Name:</td>
        <td><input type="text" name="first_name"
    	onKeyUp = "checkInput('fntick')"/></td>
    	<td align="left"><div id="fntick" style="display:none;">TICK</div></td>
      </tr>
    </table>
    This function works when you type in something to the text box the word TICK comes up. The problem is that if you back space the word TICK is still there.

    This code below works fine but its not a function:
    Code:
    <table>
    <tr>
    	    <td width="200">Last Name:</td>
    	    <td><input type="text" name="last_name" 
    		onKeyUp = "if (this.value != '') {document.getElementById('lntick').style.display = 'inline'; }else{document.getElementById('lntick').style.display = 'none'; }"/></td>
    	<td align="left"><div id="lntick" style="display:none;">TICK</div></td>
    	  </tr>
    </table>

    So if anyone can help fix my problem with the function.
    Thanks

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Actually, it doesn't work. "this" doesn't work in a case like that.
    Code:
    <script>
    function checkInput(div_name,e) {
    if (e.value != '') {alert(this.value);
    document.getElementById(div_name).style.display ='inline'; 
    } else {
    document.getElementById(div_name).style.display ='none'; 	
    }
    }
    </script>
    Code:
    <table>
    <tr>
        <td width="200">First Name:</td>
        <td><input type="text" name="first_name"
    	onkeyup = "checkInput('fntick',this)"/></td>
    	<td align="left"><div id="fntick" style="display:none;">TICK</div></td>
      </tr>
    </table>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles