Javascript help
#1
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.
[Image: h2.png]
Visit my profile here.
#2
Maybe this?

Code:
document.getElementsByName('name').value;
#3
(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
[Image: h2.png]
Visit my profile here.
#4
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
[Image: ETQjSgL.jpg]
Made by Me X | Give a Rep, You May Get Something in Return *wink* ,Click Here
#5
(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
[Image: h2.png]
Visit my profile here.


Forum Jump:


Users browsing this thread: 1 Guest(s)