?
Solved

Javascript setting a textbox font to italic

Posted on 2010-01-11
13
Medium Priority
?
625 Views
Last Modified: 2012-05-08
I don't have my code in front of me but I am using the GetElementID()...I have code that is setting a textbox to readonly = true, now I also want to change the font of the textbox to Italic...how do I do this?
0
Comment
Question by:cenetadmin
[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
  • 3
  • 3
  • +2
13 Comments
 
LVL 18

Expert Comment

by:Morcalavin
ID: 26285659

document.getElementById('yourtextboxid').style.fontStyle = 'italic';

Open in new window

0
 
LVL 14

Expert Comment

by:ajitha75
ID: 26285669
Try this....

document.getElementById("label1").setAttribute("style","font-style: italic");
0
 
LVL 82

Expert Comment

by:hielo
ID: 26285683
try:
obj.style.fontStyle='italic';

where obj is a reference to the element you get from GetElementID()
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:cenetadmin
ID: 26285690
I don't have my code in front of me...but it seems like I am doing some sort of Write statement for all of the javascript lines...how would it effect the syntax?...sorry, can't remember the syntax of the 'write'.
0
 
LVL 82

Expert Comment

by:hielo
ID: 26285728
you mean something like:
document.write("<input type='text' value='hello' style='font-style:italic;'/>")

Open in new window

0
 
LVL 11

Expert Comment

by:princeatapi
ID: 26285740
document.getElementById("tBox").style.fontStyle ="Italic"
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 26285748
Hard to say without the code.  Can't tell if you are writing out javascript or html elements.  If it was javascript it would look something like this:


document.write("<script type=\"text/javascript\">document.getElementById('textbox').style.fontStyle = 'italic';<\/script>");

Open in new window

0
 

Author Comment

by:cenetadmin
ID: 26286716
here is a sample line where I am setting the field as readonly...

            s.AppendFormat("    document.getElementById('{0}').readOnly = false;\n", Me.txtPropertyInfo_Taxes_DueYear1_MF.ClientID)
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 26286793
I'm assuming s is a stringbuilder?

s.AppendFormat("    document.getElementById('{0}').style.display = 'italic';\n", Me.txtPropertyInfo_Taxes_DueYear1_MF.ClientID)

Open in new window

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 26286801
Woops.  should be this:

s.AppendFormat("    document.getElementById('{0}').style.fontStyle = 'italic';\n", Me.txtPropertyInfo_Taxes_DueYear1_MF.ClientID)

Open in new window

0
 

Author Comment

by:cenetadmin
ID: 26286819
thanks, will try later this evening and reward if it works. Thanks
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 26286870
try:
  s.AppendFormat("    document.getElementById('{0}').readOnly = false; document.getElementById('{0}').style.fontStyle='italic'; \n", Me.txtPropertyInfo_Taxes_DueYear1_MF.ClientID)
0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 26293268
Just out of curiosity, why didn't you split the points?  hielo and my code was pretty much the same, with the exception of the script being appended to the same line, instead of two?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

764 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