PDA

View Full Version : controlling form output


BillyShope
11-13-2005, 07:02 AM
I'm a newbie with JavaScript and have written, on NotePad, a program which calculates a car's acceleration. After receiving the car's specifications, the JavaScript "goes through the gears" one foot at a time.

At the present time, everything is on my computer and I really doubt if it'll ever be available on the Internet. Please keep this in mind when offering tips on linking.

So, here's my problem: I've filled the form with initial values for all the parameters and, when the program is opened, the output appears below the form. I've been forced to title this "Sample Output For Initial Values" because, when a change is made, the output goes to a new window. What I'd like, of course, is for that output to change with any parameter change (as in EXCEL).

How's it done?

As an alternative, I've tried a frameset, with the HTML in one frame and the JavaScript in another, but have been unable to get the info from one frame source to the other. Need help on this problem, also.

Please help a newbie!

Kalessin
11-13-2005, 08:23 AM
What I would do in this situation is label the output fields with span tags, giving them unique IDs. For example, if you set your initial output HTML to readTotal: <span id="totalfield">53.2</span>you could then use JavaScript to change the value (called by onSubmit() or similar) by using document.getElementById('totalfield').innerHTML='76.5';Let me know if this helps.

Kal

BillyShope
11-13-2005, 01:25 PM
Thanks, Kal, but that doesn't seem to be what I need. Or, at least, I can't get it to work for me. Here's as simple an example as I could come up with:
<html>
<head>
<script language="JavaScript">
function y(){x=1*document.form1.xx.value;
document.write(x)};
</script>
</head>
<body>
<form name="form1"><p><b>Value of 'x' = </b><input type="text" size="20" name="xx" value="5"></p></form>
<p><input type="button" value="Display" onClick="y();"></p>
<p><script language="JavaScript">y()</script></p>
</body>
</html>
When opened, you get the form with a "5" already in the box, then the button , and, at the bottom, the "5" repeated again. When you change the form value to, say, a "6" and hit "Display," you get a new window with the number "6." What I'd like, after the change and click on "Display," would be the number "6" to appear at the bottom of the first page instead of the "5."

I hope that's a little clearer.

Kalessin
11-13-2005, 05:29 PM
The problem with using document.write() is that if it is called after the page has finished loading, it starts writing a new page.

Here's your code, modified to show my example.<html>
<head>
<script language="JavaScript">
function writeTheAnswer()
{
document.getElementById('theAnswer').innerHTML=1*document.form1.xx.value;
}
</script>
</head>
<body onload="writeTheAnswer()">
<form name="form1">
<p><b>Value of 'x' = </b><input type="text" size="20" name="xx" value="5"></p>
</form>
<p><input type="button" value="Display" onClick="writeTheAnswer()"></p>
<p><span id="theAnswer">&nbsp;</span></p>
</body>
</html>Hope that helps you to understand the solution. Let me know how you get on.

Kal

BillyShope
11-13-2005, 11:58 PM
Thanks a lot, Kal!! That's just what I needed.

I can get only so much from the Sam's and Dummie books. Besides, they tend to provide only "text" examples and I'm more interested in number crunching.

Thanks again.

BillyShope
11-14-2005, 09:22 AM
Sorry to keep bugging you on this, Kal, but I need just a bit more help.

I've figured out how to nest functions so I can bring in more than one variable, but I'm unable to do anything (add, multiply, etc.) with them.

How do you "grap 'hold" of that "getElement" business in order to manipulate it?

BillyShope
11-14-2005, 10:38 AM
Never mind. I figured it out.

I'm certain I didn't have this much trouble learning a programming language back in the fifties and sixties. I guess I fit the "old dog/new tricks" paradigm.

Kalessin
11-14-2005, 06:14 PM
I guess programming with punch cards is a hell of an incentive to get it right first time :)

BillyShope
11-14-2005, 08:56 PM
In 1958, I entered some data in the wrong field and the Chrysler Engineering IBM 360 (630???...I might not even be close) was out of commission for a couple of days.