I am trying to write a html page with 3 fields that a user can choose to input a number into any of the three fields and the calculations are instantly performed and displayed.
The first field is a number. The second field is that first field multiplied by 5. The third field is the square root of the first field.
I've been tripped up on a couple issues as I'm new to javascript and have only taken a few programming classes in the past.
1) My first stumbling block, the onChange command. Couldn't get it working so I instead discovered and have used onFocus and onBlur. Anyone have a good tutorial on how to use onChange correctly? w3schools only confused me more with their explanation.
2) What approach should I use to allow a number to be entered into any of the three fields and have necessary calculations be displayed in all the fields?
3) I'm not asking for anyone to write this script out for me. I'm a beginner trying to complete this as an assignment for one of my classes. I'm looking for advice and guidance on how to make this work. What I've written so far is pasted below. The script works if a number is entered into the first box, but I need to be able to have a number entered into any of the boxes and have the calculations displayed instantly and I would appreciate any feedback on my mistakes.
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
// 2nd box is 5 times the value of the number in box 1
function calcMultiply() {
one = document.myForm.inputBox1.value;
document.myForm.inputBox2.value = (one * 5);
}
// 3rd box that equals the square root of number in box 1
function calcSquareRoot(){
document.myForm.inputBox3.value = Math.sqrt(one);
}
</SCRIPT>
</HEAD>
<BODY onLoad ="document.myForm.inputBox2.focus()">
<div style="width: 200px; text-align: center;">
<form name="myForm">
<!-- First box can have any number entered to be calculated -->
<P> A Number: </P>
<input class="right" type=text name="inputBox1" value=""><BR>
<!-- 2nd box must be 5 times the value of number in the first box -->
<P> Number Multiplied by 5: </P>
<input class="right" type=text name="inputBox2" value="" onFocus="calcMultiply();" onBlur="calcMultiply();"><BR>
<!-- 3rd box must be the square root of number in the first box -->
<P> Square Root of the Number: </P>
<input class="right" type=text name="inputBox3" value="" onFocus="calcSquareRoot();" onBlur="calcSquareRoot();"><BR>
</BODY>
</HTML>
At work we still have a couple of people that use a version of AutoCAD LT purchased in 1994.
This predates Windows 95 and works fine on versions of Windows up to XP. Its long since run in an locked down isolated XP VM, accessible via RDP.
I did install LibreCAD for them, however they said it was just too different to get to grips with. In all fairness one of them is now 75 and the other is almost 60.
Nothing is stopping you from continuing with your testing cadence.
If updates are released every 2 weeks instead of 4, and you test once every 4 weeks, the exact same amount of patches will still be available for you in those 4 weeks.
For example:
Before
4th week - patch 1, 2, 3, 4
After
2nd week - patch 1 and 2
4th week - patch 3 and 4
Still the same amount after 4.
Everyone else has said it. I'm gonna say it - you don't know what you're talking about.
I do. I have two laptops. One work, one personal. I have access to two more laptops - both personal. At home I manually update my personal laptop when I see on Neowin that there is an update - I carry on and only apply the updates when I am ready. My work one only updates when my workplace decides to send it - I carry on and only apply the updates (when they actually arrive, which is usually days after the release) when I switch off the laptop at the end of the day as usual. The two other personal laptops only get updated when I get to it which is rarely - the people who own them carry on using them until I get to it and update them.
All of the browsers on all laptops are configured to restore the tabs when launched.
Google and Microsoft have changed from 6 weeks to 4, and it looks like it's going to move to 2. None of these changes affect how any of these browsers on the laptops are used. Not one jot.
My advice to you is stop panicking whenever you see an update. Just carry on with what you're doing. This even benefits you in a way - from your comment you sound like you don't like the changes or the frivolous new features - great - then carry on as before!
Question
Scotch Tape
I am trying to write a html page with 3 fields that a user can choose to input a number into any of the three fields and the calculations are instantly performed and displayed.
The first field is a number. The second field is that first field multiplied by 5. The third field is the square root of the first field.
I've been tripped up on a couple issues as I'm new to javascript and have only taken a few programming classes in the past.
1) My first stumbling block, the onChange command. Couldn't get it working so I instead discovered and have used onFocus and onBlur. Anyone have a good tutorial on how to use onChange correctly? w3schools only confused me more with their explanation.
2) What approach should I use to allow a number to be entered into any of the three fields and have necessary calculations be displayed in all the fields?
3) I'm not asking for anyone to write this script out for me. I'm a beginner trying to complete this as an assignment for one of my classes. I'm looking for advice and guidance on how to make this work. What I've written so far is pasted below. The script works if a number is entered into the first box, but I need to be able to have a number entered into any of the boxes and have the calculations displayed instantly and I would appreciate any feedback on my mistakes.
<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> // 2nd box is 5 times the value of the number in box 1 function calcMultiply() { one = document.myForm.inputBox1.value; document.myForm.inputBox2.value = (one * 5); } // 3rd box that equals the square root of number in box 1 function calcSquareRoot(){ document.myForm.inputBox3.value = Math.sqrt(one); } </SCRIPT> </HEAD> <BODY onLoad ="document.myForm.inputBox2.focus()"> <div style="width: 200px; text-align: center;"> <form name="myForm"> <!-- First box can have any number entered to be calculated --> <P> A Number: </P> <input class="right" type=text name="inputBox1" value=""><BR> <!-- 2nd box must be 5 times the value of number in the first box --> <P> Number Multiplied by 5: </P> <input class="right" type=text name="inputBox2" value="" onFocus="calcMultiply();" onBlur="calcMultiply();"><BR> <!-- 3rd box must be the square root of number in the first box --> <P> Square Root of the Number: </P> <input class="right" type=text name="inputBox3" value="" onFocus="calcSquareRoot();" onBlur="calcSquareRoot();"><BR> </BODY> </HTML>Thank you.
Link to comment
https://www.neowin.net/forum/topic/1055910-onchange-and-calculating-fields/Share on other sites
2 answers to this question
Recommended Posts