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>
Samsung Galaxy XR arrives in the UK with new AI and enterprise features by Fiza Ali
Samsung is bringing its Galaxy XR headset to the UK several months after the device made its debut as the first headset built on Google's Android XR platform. The headset was first teased in late 2024 alongside Google's introduction of Android XR before making its commercial debut in 2025.
Developed in collaboration with Google and Qualcomm, Galaxy XR combines mixed reality experiences with Gemini-powered AI features, allowing users to interact with digital content using voice, gestures, and visual inputs. While the hardware itself remains largely unchanged from the version Samsung unveiled last year, the company is using the UK launch to spotlight several software enhancements that have arrived through recent updates.
Among the most notable additions is deeper integration with Google's ecosystem. Galaxy XR users can explore destinations through Google Maps' Immersive View, receiving AI-powered recommendations and contextual information from Gemini while navigating virtual environments. Furthermore, entertainment experiences have also expanded; users can watch 180-degree and 360-degree videos on YouTube, browse spatial content converted into 3D, and ask Gemini questions about on-screen content without interrupting playback.
Samsung is also highlighting mixed-reality features such as Circle to Search, which allows users to identify real-world objects through hand gestures while using the headset's video pass-through mode. Another feature automatically converts photos and videos into spatial 3D experiences. Moreover, the headset now also supports Android Enterprise, allowing organisations to manage deployments using existing Android management tools.
Annika Bizon, Vice President, Product and Marketing, Mobile Experience, Samsung UK & Ireland, talked about the device, stating:
The headset is powered by Qualcomm's Snapdragon XR2+ Gen 2 platform and features dual 4K Micro-OLED displays. The tech giant says that users can expect up to 2.5 hours of battery life. Samsung also confirmed that Galaxy XR will continue receiving software and security updates as the company works alongside Google and Qualcomm to expand the Android XR ecosystem.
Galaxy XR is now available for pre-order and will go on sale on 8 July. Customers interested in trying the headset before launch can visit Samsung KX in London and selected Samsung Experience Stores from 17 June. Finally, the company will also host a livestream on 19 June showcasing the headset's capabilities and answering questions from prospective customers.
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