Solved

Change font size with JavaScript via INPUT FORM

Posted on 2008-10-24
13
834 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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 100 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 300 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 100 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 Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

705 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