Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    make a text in 'text area' italics

    hey
    im new to javascript and im working in this function , i can't get it work
    here is my code
    PHP Code:
     <SCRIPT LANGUAGE="JavaScript">

    function 
    text(form1) {
            var 
    document.form1.diary.value;
            
    j.italics();
            
    document.form1.diary.value ;
                                   }
    </SCRIPT> 
    whats the problem ?
    Last edited by dxtr; 12-11-2011 at 04:47 PM.

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    italic() just adds <i> tags to a string, but in form elements HTML tags are not parsed.

    document.form1.diary.style.fontStyle = 'italic';

  • Users who have thanked Logic Ali for this post:

    dxtr (12-11-2011)

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thnx it works
    now i want to make something like this , if the text is not italic , it will be italic , else it will be not italic
    PHP Code:
    <script type="text/javascript">
    function 
    it()
    {
                if(
    document.getElementById("it").style.fontStyle != "italic")
                {  
    document.getElementById("it").style.fontStyle "italic" ;}
                else { 
    document.getElementById("it").style.fontStyle != "italic" ; }
    }
    </script> 
    it just makes it italic

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    The name of a global object/variable must not conflict with any element ID.

    This function requires an ID passed to it. That way it can be used on any element.

    Code:
    <script type="text/javascript">
    
    function ital( id )
    {
      var style = document.getElementById( id ).style;
    
      style.fontStyle = ( style.fontStyle == 'italic' ? 'normal' : 'italic' ) ;
    }
    
    </script>

  • Users who have thanked Logic Ali for this post:

    dxtr (12-11-2011)

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    can u plz explain to me this part , i don't get it
    PHP Code:
      style.fontStyle = ( style.fontStyle == 'italic' 'normal' 'italic' ) ; 

  • #6
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by dxtr View Post
    can u plz explain to me this part , i don't get it
    PHP Code:
      style.fontStyle = ( style.fontStyle == 'italic' 'normal' 'italic' ) ; 
    https://developer.mozilla.org/en/Cor...ional_operator

  • #7
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you , i got it


  •  

    Posting Permissions

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