SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with JAVASCRIPT

    HI everybody,
    i'm trying to change the font-weight in the text of an anchor but I'm failing.
    This is the code:
    ......
    <script language="JavaScript1.2">
    function bordato(obj)
    {
    obj.style.font-weight = "Bold";
    }
    </script>

    </head>

    <body id="corpo">
    <a name="prova" id="prova" ondblclick="bordato(this)">HI</a>
    ........

    The goal is to have HI with the BOLD decoration.
    I have explorer 6

    Is there someone who can help me???
    THANK YOU
    Giampiero

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try "obj.style.fontWeight"

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IT WORKS!!!!

    THANK YOU VERY MUCH.

    May I ask you another thing?
    If I have a textarea and in this area there's written "Hi I'm Giampiero".
    If I would like to change ONLY the word Giampiero in bold way how can i do it??

    THANK YOU SO MUCH
    Bye
    Giampiero

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>Giampiero</title>
    <style type="text/css">
    
    textarea {
              font: bold 16px "comic sans ms";
              color: #fff;
              background: #574;
              overflow: hidden;
              border: 3px black dashed;
              cursor: pointer;
             }
    
    </style>
    </head>
    <body>
    <textarea rows="13" cols="30" title="click me!" ondblclick="this.value=this.value.replace(/(giampiero)/gi, 'GIAMPIERO')">
    
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    > Hi I'm Giampiero.
    </textarea>
    </body>
    </html>
    
    ::: certified wild guess :::

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, ADIOS.
    Well the problem is that in this way you change all the text in the textarea.
    I need to change only a specified word in the text.
    I mean.
    If un the textarea there's written:

    Hi I'm Giampiero

    I'd like to select Hi make it bold (I'm sorry about my english)

    What I'd like to know is how can I take only the value selected and not all the value in the textarea.

    I hope I'm clear, I know my english isn't so good.

    Thank you so much

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By 'bold' I hope you mean 'uppercase'...textareas don't do HTML.
    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript">
    
    function setSelectionRange(input, selectionStart, selectionEnd)
    {
    	if (input.setSelectionRange)
    	{
    		input.focus();
    		input.setSelectionRange(selectionStart, selectionEnd);
    	}
    	else if (input.createTextRange)
    	{
    		var range = input.createTextRange();
    		range.collapse(true);
    		range.moveEnd('character', selectionEnd);
    		range.moveStart('character', selectionStart);
    		range.select();
    	}
    }
    
    function setCaretToPos (input, pos)
    {
    	setSelectionRange(input, pos, pos);
    }
    
    function UPPERCASEit (input)
    {
    	if (input.setSelectionRange)
    	{
    		var selectionStart = input.selectionStart;
    		var selectionEnd = input.selectionEnd;
    		var replaceString = input.value.substring(selectionStart, selectionEnd).toUpperCase();
    		input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);
    		setCaretToPos(input, selectionStart + replaceString.length);
    	}
    	else if (document.selection)
    	{
    		var range = document.selection.createRange();
    		if (range.parentElement() == input)
    		{
    			var isCollapsed = range.text == '';
    			range.text = range.text.toUpperCase();
    			if (!isCollapsed)
    			{
    				range.moveStart('character', - range.text.length);
    				range.select();
    			}
    		}
    	}
    }
    
    </script>
    </head>
    <body>
    <form style="width:780px;margin:40px auto;text-align:center;padding:18px;background:buttonface;border:3px #fff groove;">
    <textarea name="TA" rows="14" cols="90" wrap="virtual" style="margin:8px;padding:5px;">
    Beverly Hills, CA - Giampiero will be a presenter at the 76th Academy Awards, telecast producer Joe Roth announced today. It will be his fourth OscarŽ show appearance.
    
    Giampiero currently is currently in pre-production on "Miss Congeniality 2" and just finished filming "Crash." His other film credits include "Two Weeks Notice," "The Divine Secrets of the Ya-Ya Sisterhood," "Miss Congeniality," "Hope Floats," "While You Were Sleeping" and "Speed."
    
    Academy Awards for outstanding film achievements of 2003 will be presented on February 29, 2004, at the Kodak Theatre at Hollywood & HighlandŽ and will be televised live by the ABC Television Network beginning at 5 p.m. (PST) with a half-hour arrivals segment. Information about the 76th Annual Academy Awards can be accessed on line at <oscar.com>
    </textarea>
    <input type="button" value="UPPERCASE selected text" onclick="UPPERCASEit(TA)" />
    </form>
    </body>
    </html>
    
    Not as easy as it looks, eh?
    ::: certified wild guess :::

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, not easy.

    No I mean Bold, but it's the same don't worry.
    IT WORKS, FANTASTIC.
    THANK YOU SO MUCH.
    Now I'm going to study your fantastic code.
    I'll tell you something about it.
    See you very very soon.
    Giampiero

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very very interesting.
    I've never written code like you.
    But Adios, you're in trouble now
    I'm sorry I'm Italian and I like jokes.
    This ability that you have showed to me, I'll try to use it if you are agree.
    The real problem that I have is this.
    I have to build a control panel that allow the users to write a text (in a text area obviously) and then clicking on a button build a real html page with that text.
    The server side language I'm going to use is PHP.
    I'd like to allow to the users to have a chance to select a word and give it a characteristic (like bold, Uppercase,italic and so on).
    I could use PHP to do it but I'd to reload the page to have the result on the screen.
    So I decided to try to use Javascript that is a client side language as you already know.
    Do you understand now my goal??
    Select a word in a text area and change it in italic or whatever you think.
    THE purpose of this control panel is to generate an html page with the text and with all the characteristics I put it on (like italic, uppercase and so on in some words in the text)
    IF YOU CAN HELP ME you're welcome.
    THANK YOU SO MUCH for your help.
    I'm going to study very hardly your code to try to reach my aim.
    Bye
    Giampiero

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI Adios, again me.
    Your code is fantastic.
    It Sure that I did a good step to reach my aim.
    Thank you
    If you can still help me (see my previous mail) I'll thank you

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ...join the club.

    ciao, adios
    ::: certified wild guess :::

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANKS A LOT.
    I appreciated so much your help.
    Now I have a very good start to solve my problem.
    See you
    Giampiero

  12. #12
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Adios,
    I'm doing well after your help.
    I have a question for you.
    I can't find the createRange method in my javascript guide (by Netscape).
    Where did you find it??
    This line:
    var range = document.selection.createRange();
    it's completely unknown to me.
    Where can I find a guide that have these informations on internet??
    Thanks again
    Giampiero

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I make a question and I answer to my question.
    I'm crazy.
    I discovered a world about these arguments.
    I've just found in a forum someone with your nick that answered about these tips (forum is on forums.devshed.com).
    He (you??) advises to go to these sites:

    http://www.webreference.com/js/column12/
    http://www.pbwizard.com/Articles/Moz...ct_Article.htm
    I went to visit w3.org and msdn library there's a new world for me to discover.
    Thank to you.
    Bye

    P.S: I hope someone else is reading this forum

    Quote Originally Posted by jampierre
    Hi Adios,
    I'm doing well after your help.
    I have a question for you.
    I can't find the createRange method in my javascript guide (by Netscape).
    Where did you find it??
    This line:
    var range = document.selection.createRange();
    it's completely unknown to me.
    Where can I find a guide that have these informations on internet??
    Thanks again
    Giampiero

  14. #14
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I make a question and I answer to my question.
    I'm crazy.
    Matto! Me too.

    Yeah, I'm all over the place.

    What was the question?
    ::: certified wild guess :::

  15. #15
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    italy
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No no don't worry, non more questions.
    I tell you again, THANK YOU.
    Thank you very much.
    See you
    Bye Giampiero from Italy.


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
  •