Home > database >  how to disable auto-change inputs in JS
how to disable auto-change inputs in JS

Time:12-13

I am making a tool that requires a checkbox but when I place the value of the checkbox in an if statement, the checkbox auto-checks I don't know why. Is there a way to disable the auto-change when putting an input value in an if statement?

HTML:

> <!DOCTYPE html>
> <html>
>   <head>
>       <title>Minecraft Portal Relocation</title>
>   </head>
>   <body >
>             <img src="https://art.pixilart.com/c12a6ff21a0b6f5.png" width="100px" align="right">
>         <br>
>         <header>
>           <h1>Minecraft Portal Relocation</h1>
>         </header>
>         <section >
>         <b>Portal relocations in minecraft can be very useful when traversing the overworld quickly, as when you go a block in the nether, you go 8 blocks in the overworld and this page will explain how to use this fact, why to use it and perhaps when to use it.</b>
>         </section><br />
>         <section>
>         <b>Chapters:</b>
>         <ol>
>             <li>Why to use the portal relocation?</li>
>             <li>When should you use portal relocation?</li>
>             <li>How to use portal relocation?</li>
>             <li>Why is it commonly used for speedrunners and hardcore players?</li>
>             <li>How some people think how portal relocation works.</li>
>             <li>Helpful tools to show how portal relocation works.</li>
>         </ol>
>         <br>
>         <h1 >Why to use the portal relocation?</h1>
>         <br>
>         <b>Portal relocations are a great way to move around, especially when you want to move great distances in a short amount to time. People use the portal relocation to quicken transportation around the overworld as whatever they use to roam around gets timesed by 8 which could make elytra and rocket travel very fast.</b>
>         <br>
>         <br>
>         <b>People commonly use this sort of transport to go around huge distances with just 8 times less hassle in the nether than the overworld. For example, going 1,000 blocks can take an average of 1~ minutes by elytra but 5-10~ minutes by boat depending if there is a load of obstacles. Walking travel is also extremely slow in the overworld but speeds up by 8 in the nether but make sure to bring spare obsidian so you can build the new portal.</b>
>         <br>
>         <h1>When should you use portal relocation?</h1>
>         <br>
>         <b>You should use portals late game when wanting to travel far places like to your base or a structure that is very far, you can use the portals anytime but it is recommended in late game as it is important to get from one place to another in just a snap. Quick transporting is mainly useful for anyone that doesn't like to wait or is speedrunning as it can quicken the time from point A to Point B.</b>
>         <br>
>         <h1>How to use portal relocation?</h1>
>         <br>
>         <b>Using this fact is as simple as learning it, as 1 block in the nether is 8 blocks in the overworld, it can be very useful to build one of these transports. You need 10-14 blocks of obsidian (don't do more than 4*5 unless you are making a ghast farm, else you are just painfully wasting obsidian) to build a portal so make sure you have plenty, then you just find the coordinates of your current location and place a portal there, divide the coordinates of both points by 8 and then find both portals to link them.</b>
>         <br>
>         <h1>Why is it commonly used for speedrunners and hardcore players?</h1>
>         <br>
>         <b>Since portal transportation is very easy to do and is extremely quick, you can always build it if you have obsidian on you, hardcore players use portals to get to places very quick to create big projects that needs plenty of material from different areas. Manhunts also can use this to get away really quick and continue to beat the game whilst the hunters are yet miles away. This shows that this wonderful fact is very purposeful and essential for any explorer.</b>
>         <br>
>         <h1>How some people think how portal relocation works.</h1>
>         <br>
>         <b>Some people don't really think about the lore behind the portals and the 1 block nether = 8 block overworld fact. But some people that I searched for on google came from <a href="https://www.reddit.com/r/Minecraft/comments/gq1gid/why_one_block_in_the_nether_is_8_blocks_in_the/?utm_source=BD&utm_medium=Search&utm_name=Bing&utm_content=PSR1">reddit</a> and showed this picture that actually puts a bit of thought into it:</b>
>         <br>
>         <br>
>         <img src="https://preview.redd.it/hc8rpbjy9t051.png?width=960&crop=smart&auto=webp&s=30835928992bf43ffb14c212a9c00596ab4d72c0" width="80%" >
>         <br>
>         <br>
>         <b>What it shows is how the distancing could've worked and actually looks like it could be the case, but as the void is below the bedrock, it might not be 100% true but it is a very good demonstration.</b>
>         <br>
>         <h1>Helpful tools to show how portal relocation works.</h1>
>         <br>
>         <h2>Distance Converter</h2>
>         <label for="N-O">Nether To Overworld? </label>
>         <input type="checkbox" id="N-O">
>         <br>
>         <br>
>         <label for="AXCoord">Point AX: </label>
>         <input type="number" id="AXCoord" placeholder="0" min="-3000000" max="3000000" value="0">
>         <label for="AYCoord">Point AY: </label>
>         <input type="number" id="AYCoord" placeholder="0" min="-3000000" max="3000000" value="0">
>         <br>
>         <br>
>         <label for="BXCoord">Point BX: </label>
>         <input type="number" id="BXCoord" placeholder="0" min="-3000000" max="3000000" value="0">
>         <label for="ACoord">Point BY: </label>
>         <input type="number" id="BYCoord" placeholder="0" min="-3000000" max="3000000" value="0">
>         <br>
>         <br>
>         <button onclick="SendInfo()">Convert</button>
>     </section>
>   </body>
> </html>

CSS:

> h1, h2 {
> font-family: Arial, Helvetica, sans-serif;
> background: linear-gradient(to right, #9f9f9f, #ffffff, #9f9f9f);
> -webkit-text-fill-color: transparent;
> -webkit-background-clip: text;
> text-shadow: 0px 0px 5px #2c2c2c;
> }
> .Descriptor {
> border: 5px solid white;
> border-radius: 10px;
> border-width: 2.5px;
> }
> body {
> color: white;
> }
> section {
> font-family: 'Calibri';
> }
> .gradient_bg {
>   background: linear-gradient(-45deg, #000000,#434343,#7f7f7f);
>   background-size: 400% 800%;
>   -webkit-animation: gradient 15s ease infinite;
> animation: gradient 15s ease infinite;
>   height: 100vh;
> }
> @-webkit-keyframes gradient {
>   0% {
> background-position: 0% 50%;
>   }
>   50% {
> background-position: 100% 50%;
>   }
>   100% {
> background-position: 0% 50%;
>   }
> }
>  
> @keyframes gradient {
>   0% {
> background-position: 0% 50%;
>   }
>   50% {
> background-position: 100% 50%;
>   }
>   100% {
> background-position: 0% 50%;
>   }
> }
> 
> .Chap1 {
> font-size: 20px;
> }
> .imgborder {
> border: 5px solid black;
> border-radius: 10px;
> }

JS: (Main problem)

> //Credits to derek from StackOverflow for the code, https://stackoverflow.com/questions/39884915/getelementbyid-returns-nan.
> 
> function SendInfo() {
> //alert(calcCrow(parseInt(document.getElementById("AXCoord").value),parseInt(document.getElementById("AYCoord").value),parseInt(document.getElementById("BXCoord").value),parseInt(document.getElementById("BYCoord").value)).toFixed(1) / 100);
> var CoordDistVar = calcCrow(parseInt(document.getElementById("AXCoord").value),parseInt(document.getElementById("AYCoord").value),parseInt(document.getElementById("BXCoord").value),parseInt(document.getElementById("BYCoord").value)).toFixed(1) / 100
> if (document.getElementById("N-O").checked = true){
> alert("checked")
>     }else{
> alert("not checked")
>     }
>     //This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
> function calcCrow(lat1, lon1, lat2, lon2) 
>     {
> var R = 6371; // km
> var dLat = toRad(lat2-lat1);
> var dLon = toRad(lon2-lon1);
> var lat1 = toRad(lat1);
> var lat2 = toRad(lat2);
> 
> var a = Math.sin(dLat/2) * Math.sin(dLat/2)  
> Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
> var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
> var d = R * c;
> return d;
> 
> 
> Converts numeric degrees to radians
> function toRad(Value) 
> 
> return Value * Math.PI / 180;
> 
>     }

It looks correct but it isn't, I tried to search online but to no avail... it seemed like checked is the only value that is available. Is there a fix?

I was making a selection checkbox so you can pick a different value but instead when I used an if statement, it kept as checked and when I clicked a button or anything that isn't a checkbox, it reset to the default (checked). So the only output was True.

This is my whole page with the error:

//Credits to derek from StackOverflow for the code, https://stackoverflow.com/questions/39884915/getelementbyid-returns-nan.

function SendInfo() {
//alert(calcCrow(parseInt(document.getElementById("AXCoord").value),parseInt(document.getElementById("AYCoord").value),parseInt(document.getElementById("BXCoord").value),parseInt(document.getElementById("BYCoord").value)).toFixed(1) / 100);
    var CoordDistVar = calcCrow(parseInt(document.getElementById("AXCoord").value),parseInt(document.getElementById("AYCoord").value),parseInt(document.getElementById("BXCoord").value),parseInt(document.getElementById("BYCoord").value)).toFixed(1) / 100
    if (document.getElementById("N-O").checked = true){
        alert("checked")
    }else{
        alert("not checked")
    }
    //This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
    function calcCrow(lat1, lon1, lat2, lon2) 
    {
      var R = 6371; // km
      var dLat = toRad(lat2-lat1);
      var dLon = toRad(lon2-lon1);
      var lat1 = toRad(lat1);
      var lat2 = toRad(lat2);

      var a = Math.sin(dLat/2) * Math.sin(dLat/2)  
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); 
      var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
      var d = R * c;
      return d;
    }

    // Converts numeric degrees to radians
    function toRad(Value) 
    {
        return Value * Math.PI / 180;
    }
    }
h1, h2 {
font-family: Arial, Helvetica, sans-serif;
background: linear-gradient(to right, #9f9f9f, #ffffff, #9f9f9f);
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
text-shadow: 0px 0px 5px #2c2c2c;
}
.Descriptor {
border: 5px solid white;
border-radius: 10px;
border-width: 2.5px;
}
body {
color: white;
}
section {
font-family: 'Calibri';
}
.gradient_bg {
    background: linear-gradient(-45deg, #000000,#434343,#7f7f7f);
    background-size: 400% 800%;
    -webkit-animation: gradient 15s ease infinite;
            animation: gradient 15s ease infinite;
    height: 100vh;
}
@-webkit-keyframes gradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}
 
@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.Chap1 {
font-size: 20px;
}
.imgborder {
border: 5px solid black;
border-radius: 10px;
}
<!DOCTYPE html>
<html>
    <head>
        <title>Minecraft Portal Relocation</title>
    </head>
    <body >
            <img src="https://art.pixilart.com/c12a6ff21a0b6f5.png" width="100px" align="right">
        <br>
        <header>
            <h1>Minecraft Portal Relocation</h1>
        </header>
        <section >
        <b>Portal relocations in minecraft can be very useful when traversing the overworld quickly, as when you go a block in the nether, you go 8 blocks in the overworld and this page will explain how to use this fact, why to use it and perhaps when to use it.</b>
        </section><br />
        <section>
        <b>Chapters:</b>
        <ol>
            <li>Why to use the portal relocation?</li>
            <li>When should you use portal relocation?</li>
            <li>How to use portal relocation?</li>
            <li>Why is it commonly used for speedrunners and hardcore players?</li>
            <li>How some people think how portal relocation works.</li>
            <li>Helpful tools to show how portal relocation works.</li>
        </ol>
        <br>
        <h1 >Why to use the portal relocation?</h1>
        <br>
        <b>Portal relocations are a great way to move around, especially when you want to move great distances in a short amount to time. People use the portal relocation to quicken transportation around the overworld as whatever they use to roam around gets timesed by 8 which could make elytra and rocket travel very fast.</b>
        <br>
        <br>
        <b>People commonly use this sort of transport to go around huge distances with just 8 times less hassle in the nether than the overworld. For example, going 1,000 blocks can take an average of 1~ minutes by elytra but 5-10~ minutes by boat depending if there is a load of obstacles. Walking travel is also extremely slow in the overworld but speeds up by 8 in the nether but make sure to bring spare obsidian so you can build the new portal.</b>
        <br>
        <h1>When should you use portal relocation?</h1>
        <br>
        <b>You should use portals late game when wanting to travel far places like to your base or a structure that is very far, you can use the portals anytime but it is recommended in late game as it is important to get from one place to another in just a snap. Quick transporting is mainly useful for anyone that doesn't like to wait or is speedrunning as it can quicken the time from point A to Point B.</b>
        <br>
        <h1>How to use portal relocation?</h1>
        <br>
        <b>Using this fact is as simple as learning it, as 1 block in the nether is 8 blocks in the overworld, it can be very useful to build one of these transports. You need 10-14 blocks of obsidian (don't do more than 4*5 unless you are making a ghast farm, else you are just painfully wasting obsidian) to build a portal so make sure you have plenty, then you just find the coordinates of your current location and place a portal there, divide the coordinates of both points by 8 and then find both portals to link them.</b>
        <br>
        <h1>Why is it commonly used for speedrunners and hardcore players?</h1>
        <br>
        <b>Since portal transportation is very easy to do and is extremely quick, you can always build it if you have obsidian on you, hardcore players use portals to get to places very quick to create big projects that needs plenty of material from different areas. Manhunts also can use this to get away really quick and continue to beat the game whilst the hunters are yet miles away. This shows that this wonderful fact is very purposeful and essential for any explorer.</b>
        <br>
        <h1>How some people think how portal relocation works.</h1>
        <br>
        <b>Some people don't really think about the lore behind the portals and the 1 block nether = 8 block overworld fact. But some people that I searched for on google came from <a href="https://www.reddit.com/r/Minecraft/comments/gq1gid/why_one_block_in_the_nether_is_8_blocks_in_the/?utm_source=BD&utm_medium=Search&utm_name=Bing&utm_content=PSR1">reddit</a> and showed this picture that actually puts a bit of thought into it:</b>
        <br>
        <br>
        <img src="https://preview.redd.it/hc8rpbjy9t051.png?width=960&crop=smart&auto=webp&s=30835928992bf43ffb14c212a9c00596ab4d72c0" width="80%" >
        <br>
        <br>
        <b>What it shows is how the distancing could've worked and actually looks like it could be the case, but as the void is below the bedrock, it might not be 100% true but it is a very good demonstration.</b>
        <br>
        <h1>Helpful tools to show how portal relocation works.</h1>
        <br>
        <h2>Distance Converter</h2>
        <label for="N-O">Nether To Overworld? </label>
        <input type="checkbox" id="N-O"><b><--- Error</b>
        <br>
        <br>
        <label for="AXCoord">Point AX: </label>
        <input type="number" id="AXCoord" placeholder="0" min="-3000000" max="3000000" value="0">
        <label for="AYCoord">Point AY: </label>
        <input type="number" id="AYCoord" placeholder="0" min="-3000000" max="3000000" value="0">
        <br>
        <br>
        <label for="BXCoord">Point BX: </label>
        <input type="number" id="BXCoord" placeholder="0" min="-3000000" max="3000000" value="0">
        <label for="ACoord">Point BY: </label>
        <input type="number" id="BYCoord" placeholder="0" min="-3000000" max="3000000" value="0">
        <br>
        <br>
        <button onclick="SendInfo()">Convert</button>
    </section>
    </body>
</html>

CodePudding user response:

if (document.getElementById("N-O").checked = true)

Should be

if (document.getElementById("N-O").checked === true)
  • Related