Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I'm trying to make a converter for sensitivity in a game. I want the user to be able to input their mouse sensitivity and game sensitivity, then their new mouse sensitivity, the click convert. I lack knowledge in Javascript, so whatever I have already will be completely broken.
JavaScript
<html>
<body>
<form>
<p>Current DPI</p>
<input id="curDpi">
</br>
<p>Current Sensitivity</p>
<input id="curSens">
</br>
<p>New DPI</p>
<input id="newDpi">
</br>
<button id="convert">Convert</button>
</br>
<p id="newSens"></p>

<script>
function convert(){
var curDpi = document.getElementById("curDpi");
var curSens = document.getElementById("curSens");
var newDpi = document.getElementById("newDpi");
var convert = curDpi.text * curSens.text / newDpi.text;
document.getElementById("newSens").innerHTML = convert;
}
document.getElementById("convert").onclick = convert();
</script>

</body>
</html>

Here's what I have. I don't know enough Javascript to have any idea what I'm doing wrong. For all I know my HTML is broken. I'm just trying to make a simple program to save people's time. I think it's to do with the multiplication. I don't think I'm getting the text from the input. But, I have no idea.
Posted

Just try the code below may be it helps.
HTML
<html>
<head>
<script language="javascript">
function convertor(){
var curDpi = document.getElementById("curDpi");
var curSens = document.getElementById("curSens");
var newDpi = document.getElementById("newDpi");
var convert = parseInt(curDpi.value) * parseInt(curSens.value) / parseInt(newDpi.value);
document.getElementById("newSens").innerHTML = convert;
}
</script>
</head>
<body>
<form>
<p>Current DPI</p>
<input id="curDpi">

<p>Current Sensitivity</p>
<input id="curSens">

<p>New DPI</p>
<input id="newDpi">

<button id="convert" onclick="return convertor()">Convert</button>

<div id="newSens"></div>
</form> 
</body>
</html>



Hope I understood your problem in a correct manner.
 
Share this answer
 
v2
Can't you write onclick directly in button, instead of binding that in javascript!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900