?
Solved

Change font size with JavaScript via INPUT FORM

Posted on 2008-10-24
13
Medium Priority
?
835 Views
Last Modified: 2012-05-05
I want to change the font size of a disabled button in a form, from 16px to 10px.
When the button is pressed I want the message to display on the button but my message is a bit too long so the message looks too large and too long. Yes, I know I can change the font size of the button message, but I want it set to 16px before pressed.

I can't get my JavaScript to work to change the font size. Please correct my code so the font size willl change in the button. If that is not possible, then show me another way to get the same result.
<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Not Active';
   }
   }
      b.style.fontSize = 10px;
   }
 
</script>
 
<input type="button" style="display:inline;font-size:16px" value="Finish" onclick="DisableButton(this);" />

Open in new window

0
Comment
Question by:Janrow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 11

Expert Comment

by:MacAnthony
ID: 22800683
If it's always gonna be the same sizes, I would just setup two classes. One for each font size and then just switch the classname of the element onclick.


<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Not Active';
   }
   }
      b.classname = 'smallertext';
   }
 
</script>
 
<style>
 
.biggertext {
font-size: 16px;
}
 
.smallertext {
font-size: 10px;
}
 
</style>
 
<input type="button" class="biggertext" value="Finish" onclick="DisableButton(this);" />

Open in new window

0
 
LVL 6

Expert Comment

by:Iced-evil
ID: 22800696
b.style.fontSize = 10px
Could you try and change the fontSize to FontSize (capital F)
0
 
LVL 82

Expert Comment

by:hielo
ID: 22800760
you need to put the value in quotes:
b.style.fontSize = "10px";
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Janrow
ID: 22800908
Thanks guys but none of these seem to be working. Get Object Expected error.
 
Here's the code I'm using. The page is working except for the font size.


 
<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Not Active';
   }
   }
      b.classname = 'smallertext';
   }
 
</script>
 
<style>
 
.biggertext {
font-size: 16px;
}
 
.smallertext {
font-size: 10px;
}
 
</style>
 
<cfoutput>
<form action="#CGI.SCRIPT_NAME#" method="post">
 
<cfif IsDefined("AutoGenerateButton") OR IsDefined("LuckySaveButton")>
<input type="submit"  name="FinishButton" value="Finish" style="display:inline;font-size:18px">
<cfelse>
<input type="submit" class="biggertext" value="Finish" onclick="DisableButton(this);" />
 
 
</cfif>
</form>

Open in new window

0
 
LVL 16

Assisted Solution

by:sh0e
sh0e earned 400 total points
ID: 22801060
What's with the extra braces?
<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Not Active';
      b.style.fontSize = '10px';
   }
 
</script>
 
<input type="button" style="display:inline;font-size:16px" value="Finish" onclick="DisableButton(this);" />

Open in new window

0
 
LVL 11

Accepted Solution

by:
MacAnthony earned 1200 total points
ID: 22801110
The extra curly brackets are probably stopping the function execution. I've tried all versions of this including setting it with:

b.style.fontSize = 10;
b.style.fontSize = '10px';

And they all work. Pretty sure it's just that small typo.
<script>
   function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Not Active';
      b.classname = 'smallertext';
   }
 
</script>

Open in new window

0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 22801115
double post, sorry sh0e
0
 
LVL 16

Expert Comment

by:sh0e
ID: 22801164
It's fine, I'm more just surprised such a silly typo made it through so many experts.  No offense intended.  Made me think I was missing something important.  At least I know it's not just me now.
0
 
LVL 44

Assisted Solution

by:scrathcyboy
scrathcyboy earned 400 total points
ID: 22801245
<input type="button" id="sizing" style="display:inline;font-size:16px" value="Finish" onclick="DisableButton(this);" />

in javascript, just do this --

document.getElementById('sizing').style.font-size = "10px";

Note 2 things -- the input tag now has a name, and the correct CSS is "font-size" not fontSize.

If you can't get it to change this way, then use a name for the input tag, and assuming a form name="form1" -- then --

<input type="button" name="sizing" style="display:inline;font-size:16px" value="Finish"
onclick="DisableButton(this);" />

document.form1.sizing.style.font-size ="10px";
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 22801269
The css element is font-size, but the correct javascript dom property is fontSize.

http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties
0
 

Author Closing Comment

by:Janrow
ID: 31509849
That did it. Yes. Just the typo kept it for working. I'll try to spread the points around, with MacAnthony getting a bit more.
0
 
LVL 44

Expert Comment

by:scrathcyboy
ID: 22801474
"That did it. Yes. Just the typo kept it for working. "

What did it -- I want to know specifically?
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 22802179
The extra brackets in the function typo.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question