SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript problem.. works fine on firefox but not on explorer :\

    I am trying to make a comments system like in Facebook.
    Its suppose to expend the textbox dynamically.
    and show the "Share" button only if something is written in the text box..
    now my problem is that on firefox it works great.
    but on explorer it doesn't expend the text box or showing the share button...
    What is the problem?

    The Code:

    js.js
    Code JavaScript:
    document.getElementById('comments').addEventListener('keyup', function () {
    	this.style.height = 0; // this is necessary to make it shrink when deleting
    	this.style.height = this.scrollHeight + 'px';
    }, false);
     
    function ShowButton(check)
    {
    	if (check == 1)
    		document.getElementById('Share').type = "submit";
    	else
    		document.getElementById('Share').type = "hidden";
    }

    the section of code on share.php
    Code PHP:
    						<tr>
    						<td colspan="2">
    							<form action="" method="post">
    							<textarea id ="comments" name="comments" style="width: 400px;,font-size: 16px;line-height: 1; height: 16px;" onFocus="if(this.value == 'Write something...') {this.value = ''; ShowButton(1);}" onBlur="if (this.value == '') {this.value = 'Write something...'; ShowButton(0);}">Write something...</textarea>
    							<br>
    							<div align=right>
    								<input id="Share" type="hidden" value="Share" class="SearchButton"  style="width:50px; height:20px; border-width:0px;"/>
    							</div>
    							</form>
    							</td>
    						</tr>

  2. #2
    SitePoint Member Yi.Sage's Avatar
    Join Date
    Nov 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "addEventListener" can not be used in ie.

    use "attachEvent" for ie.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    IE doesn't allow you to change the type after it has first been assigned. You need to delete the entire input tag and recreate it if you want to change the type in IE.

    Take a look at Self Labelling Password Fields where I have an example of how to do this which switches between type="text" and type="password". The code to change between type="submit" and type="hidden" would be similar.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •