Forum Moderators: open

Message Too Old, No Replies

Problem with JavaScript

         

romzinho2k7

3:06 pm on Jul 26, 2006 (gmt 0)

10+ Year Member



Hey friends. All right?

I am with the code below, but he is with mistake. I did not manage to discover where is. Could anybody help?

--------------------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
function Test(x, z){
if(x == "owntest"){
var a1 = document.getElementById('owntest').style;
a1.font = z;
}
document.forms.form.elements[x].value = z;
}
</script>
<body>
<form name="form" id="form">
<div id="owntest">testing...</div>
<a href="#" onclick="Test('owntest', 'bold')">Button</a>
</form>
</body>
</html>
---------------------------------------------------------------
Script changes of normal for bold, however a mistake appears on the page. What has to wrong?
Thanks

RonPK

4:01 pm on Jul 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All right.

a1.font = z;

You should probably use fontWeight. So make that line

a1.fontWeight = z;

romzinho2k7

5:22 pm on Jul 26, 2006 (gmt 0)

10+ Year Member



Hi

I was using font, because I saw a tutorial and saw that using font is possible to use so much 'bold' as 'italic' as 'normal'....

Would he have how to do it use these three in a same function?

RonPK

7:24 pm on Jul 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, you're using 'form' as name and id of an element. Such names are bound to cause confusion, either for the browser or for humans trying to read the script.

document.forms.form.elements[x].value = z;

'owntest' is not part of the elements collection of the form called 'form'. What are you trying to achieve with that line?

romzinho2k7

5:48 am on Jul 27, 2006 (gmt 0)

10+ Year Member



Without that line anything works. Neither with mistake works. I have wanting a script of this appearance, that works for I put in bold, italic and normal with an unique function.