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, 05: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';
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, 07: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>
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, 07: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
https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Expressions_and_Operators#conditional_operator
Thank you , i got it