0

Alright, so I am trying to create a countdown timer that will take a number that you put into an HTML input field and then take that, assign it to the variable x, and have it go through an equation that outputs the amount of time to be counted down.

I have the timer completely setup and everything. I have everything setup equation wise: that is, I have it setup to where I can physically set x = some number and it will countdown from the appropriate time.

The problem I am having is that I cannot seem to get it to the point where I have a some user input and that then becomes x, and then it outputs that appropriate time.

Here is my code:

<body>
        Number: <input id="num" type="text" name="number">
        <button type="button" onClick="buttonClick()">Submit</button>
        <div id='timer' />
        <script type="text/javascript">
            var x;
            var y=Math.pow(x, 2);
            var z=(y+4*x+10);
            window.onload = CreateTimer("timer", z);
        </script>
</body>

I have tried dozens of suggestions throughout the site, but none of them really had to do with what I am trying to do, and none of them worked. I have tried many different functions that take the onClick function and use things like

x=getElementbyID("num").value

and have as well as

w=getElementbyID("num");
x=w.value;

I cannot seem to think of how to do it. Any help will be much appreciated. :)

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
abyssmu
  • 165
  • 1
  • 12
  • 1
    Straight forward -> http://jsfiddle.net/GwQZD/1/ – adeneo Jan 20 '14 at 19:12
  • possible duplicate of [Javascript get input text value](http://stackoverflow.com/questions/11563638/javascript-get-input-text-value) -- please use the search before you ask a new question. – Felix Kling Jan 20 '14 at 19:18

1 Answers1

0

I think you should have a look at this documentation.

See this (from the JSFiddle recommended in the comments) :

var x = document.getElementById('num').value;
cubitouch
  • 1,929
  • 15
  • 28