...

View Full Version : make a text in 'text area' italics



dxtr
12-11-2011, 05:41 PM
hey
im new to javascript and im working in this function , i can't get it work :(
here is my code


<SCRIPT LANGUAGE="JavaScript">

function text(form1) {
var j = document.form1.diary.value;
j = j.italics();
document.form1.diary.value = j ;
}
</SCRIPT>


whats the problem :D ?

Logic Ali
12-11-2011, 06:30 PM
italic() just adds <i> tags to a string, but in form elements HTML tags are not parsed.

document.form1.diary.style.fontStyle = 'italic';

dxtr
12-11-2011, 08:04 PM
thnx it works
now i want to make something like this , if the text is not italic , it will be italic , else it will be not italic


<script type="text/javascript">
function it()
{
if(document.getElementById("it").style.fontStyle != "italic")
{ document.getElementById("it").style.fontStyle = "italic" ;}
else { document.getElementById("it").style.fontStyle != "italic" ; }
}
</script>

it just makes it italic

Logic Ali
12-11-2011, 08:25 PM
The name of a global object/variable must not conflict with any element ID.

This function requires an ID passed to it. That way it can be used on any element.


<script type="text/javascript">

function ital( id )
{
var style = document.getElementById( id ).style;

style.fontStyle = ( style.fontStyle == 'italic' ? 'normal' : 'italic' ) ;
}

</script>

dxtr
12-11-2011, 08:44 PM
can u plz explain to me this part , i don't get it


style.fontStyle = ( style.fontStyle == 'italic' ? 'normal' : 'italic' ) ;

:)

Logic Ali
12-11-2011, 08:56 PM
can u plz explain to me this part , i don't get it


style.fontStyle = ( style.fontStyle == 'italic' ? 'normal' : 'italic' ) ;

:)

https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions_and_Operators#conditional_operator

dxtr
12-11-2011, 09:30 PM
https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions_and_Operators#conditional_operator
Thank you , i got it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum