Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Javascript setting a textbox font to italic

Posted on 2010-01-11
13
Medium Priority
?
636 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
  • 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
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: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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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

581 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