Fearless Forums
Javascript help - Printable Version

+- Fearless Forums (https://fearlessrp.net)
+-- Forum: General Discussion (https://fearlessrp.net/forumdisplay.php?fid=10)
+--- Forum: Discussions (https://fearlessrp.net/forumdisplay.php?fid=4)
+---- Forum: Archive (https://fearlessrp.net/forumdisplay.php?fid=481)
+---- Thread: Javascript help (/showthread.php?tid=92948)



Javascript help - Haarek - 05-27-2019

How do I make it possible for a user of the site to input the values? 
I get I have to use <input> with a form but I can't get the js to reference the name, id or action. 
Is php the solution?

Code:
<html><body><script>

var height = 140
var storySize = 2.8

var getStories = function(storyCount){

    storyCount = height / storySize
    
    console.log("The height of the building is " + height + "m")
    console.log("The building has " + Math.trunc(storyCount) + " stories")
    console.log("the height of each story is " + storySize +"m")
    


getStories()





</script>





</body>
</html>
If I can get help solving this I will give whoever solves it 150,000$ ig 
I have tried 2 days now on and off.


RE: Javascript help - Luna - 05-27-2019

Maybe this?

Code:
document.getElementsByName('name').value;



RE: Javascript help - Haarek - 05-27-2019

(05-27-2019, 12:10 PM)Arny Wrote: Maybe this?

Code:
document.getElementsByName('name').value;


Code:
<html>
    <form>
        <input name="numb" type="number">
        <button onclick="getValue()">run</button>

    </form>
<script>

function getValue() {
 var x = document.getElementsByName("numb")[0].tagName;
    document.getElementById('show').innerHTML = x;
    
    getStories()
}

var height
var storySize = 2.8

var getStories = function(storyCount){

    storyCount = height / storySize
    
    console.log("The height of the building is " + height + "m")
    console.log("The building has " + Math.trunc(storyCount) + " stories")
    console.log("the height of each story is " + storySize +"m")
    
}
</script>
<p id="show"></p>

</body>
</html>

I've tried this now


RE: Javascript help - dawson270500 - 05-29-2019

Remove the <form> tags, that may help
Also try
var x = document.getElementById("numb").value;

You shouldn't need to put an array value on it


RE: Javascript help - Haarek - 06-02-2019

(05-29-2019, 03:01 PM)dawson270500 Wrote: Remove the <form> tags, that may help
Also try
var x = document.getElementById("numb").value;

You shouldn't need to put an array value on it

Thanks for the help. For future refrence that doesn't work as you'd expect it to.
You have to use a query selector with an addEventListener. 

It took me a long time to figure it out

best regards