Jon,
I don't think he is. I think he's just confused. Maybe he's picked up
some
stuff along the way and thought it might work.
The meaning of properties and methods may be one thing worth learning.
(David, here is a reference that might help:
http://www.w3schools.com/htmldom/dom_methods.asp .
This does not specify how to define your own properties and methods, but
doing this is probably not for beginners.)
I think that what would work here to specify a font size (if that is
what is
required) is
1. Using style=".........."
or
2. Defining a class in CSS and using class=
--
Trevor Lawrence
Canberra
Web Site
http://trevorl.mvps.org
Learning javascript is fine but look at this
<quote>
var answer = txtans
T2.value = txtans;
//document.getElementById("calcans").innerHTML = answer.fontsize(1);
</quote>
There's no way answer could have a fontsize method if it's just been
declared as a variable
Do you think he might be taking the p*ss
Hi David,
You seem to be where I was a few years ago, trying to find out what
you
can do with JavaScript, so your questions are (in some cases) pushing
me
to (re)learn myself
Anyway, keep having fun
Here is what works for me. It writes the value to an input text box
in
the same form.
<html>
<head>
<script type="text/javascript">
function sqrtornd()
{
var con = Math.sqrt(2);
with (document.forms[0]) {
T2.value = T1.value * con ;
}
}
</script>
</head>
<body>
<form name="form1" action="">
Enter Input Value: <input type="text" id="T1" value="100"
size="40" /><br>
Result [Value*sqrt(2)]: <input type="text" id="T2" value=""
size="40">
<br>
<input type="button" id="Calculate" value="Calculate"
onclick="sqrtornd()">
</form>
</body>
</html>
You could round the result,
e.g. to 3 decimal places, use:
T2.value = Math.round(T1.value * con * 1000) / 1000 ;
You wrote that you don't want it in a textbox, but in "a cell within
a
form".
After thinking about this, maybe you are trying to write to the
innerHTML
of a <input> element.
You cain't because there ain't one; innerHTML only exists for
elements
which have an opening and a closing tag,
You can use therefore use <textarea> instead of <input> and then use
innerHTML in the function
Result [Value*sqrt(2)]: <textarea rows="1" cols="10" id="T2"
style="font:
Arial;color:red;"></textarea>
The style can be as you wish, e,g, colours, font sizes, etc.
--
Trevor Lawrence
Canberra
Web Site
http://trevorl.mvps.org
I am attempting to write a value to a cell that is with in a form,
rather
than a textbox. What am I missing? I keep receiving an error.
T2.value
works, but the 'ByID' is not.
<script type="text/javascript">
function sqrtornd()
{
with (document.forms[0])
{
var con = '1.414'
var sqr = T1.value
var txtans = sqr * con
var answer = txtans
T2.value = txtans;
//document.getElementById("calcans").innerHTML =
answer.fontsize(1);
}
}
</script>
David
.