Solved

Change font size with JavaScript via INPUT FORM

Posted on 2008-10-24
13
826 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
  • 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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now