Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Member #
    27257
    So I am trying to use Javascript to change the font size of my main section using buttons for "small" "medium" and "large."

    Unfortunately, no matter how hard I try, I cant get it to work...

    Right now I have:

    <script type="text/javascript">
    function textz(n){
    bt = document.getElementById("mmainh").style.fontSize;
    bt = (n*10)+"px";
    alert(""+bt);
    }
    </script>

    <a href="javascript: textz(1);"><p style="float:left; margin-left:10px; margin-right:10px; margintop:30px;">Small</p></a>
    <a href="javascript: textz(2);"><p style="float:left; margin-left:10px; margin-right:10px; margintop:30px;">Medium</p></a>
    <a href="javascript: textz(3);"><p style="float:left; margin-left:10px; margin-right:10px; margintop:30px;">Large</p></a>

    <div id="mmainh">
    <h2>This Month</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vel quam sit amet neque vulputate dignissim eget a nu.</p>
    </div>

    This is the order of my stuff so far, and there is a lot more in my code, but nothing that should be interfering. Can anyone tell me what I am doing wrong or how to fix this?

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Try this instead:
    Code:
    function textz(n) {
        var newFontSize = eval (n * 10);
        newFontSize += "px";
        document.getElementById("mmainh").style.fontSize = newFontSize;
    }
    For the sake of speed/performance though, you should define three classes in a cascading stylesheet and use something like this:
    Code:
    document.getElementById("mmainh").className = "medium-sized";
    The other thing you should consider is that most browsers have the ability to resize text, so putting in a feature like this is all but redundant anyway. It's a nice thought, but it's redundant.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Member #
    27257
    Ok thank you!

    And I know it is redundant, I just need some sort of Java code that modifies CSS within the site because it is a school project. This is the best thing I could do because I didnt really need any CSS changing in my pet take on facebook. :P

  5. #4
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Ahhhh. That explains it.

    Tell your school they're about 7 years behind then. If you still get an A after saying that, you'll know you've earned it.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  6. #5
    Senior Member Ferro's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    386
    Member #
    14204
    Liked
    5 times
    Quote Originally Posted by Paden, post: 201232
    I just need some sort of Java code
    javaSCRIPT - different thing.
    TheGAME1264 likes this.

  7. #6
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Dude's right. I missed it the first time I read it.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  8. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Member #
    27257
    I even knew that...thats embarassing. I was tired, this website is stressing me out due to my lack of Javascript knowledge and the fact that I have a 15 page essay due next week I have barely started due to this website... :P

  9. #8
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Fill 1 page with useful copy, the last 14 with "SCREW FLANDERS" and you're done!
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:29 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com