1,105,585 Community Members

Help with Basic JavaScript please!!!

Member Avatar
alex.plouff
Newbie Poster
2 posts since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

needing help with homework - calculator using javascript

i need to grab the text from the <input> and use that number in the equation.

<script>
function runMe(){
var x == document.getElementById('input1').value;
document.write(x);
}
</script>

<body>
<form>
Enter number <input type="text" id="input1" value="">
<input type="submit" onClick="runMe">
</form>

</body>
Member Avatar
alex.plouff
Newbie Poster
2 posts since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

why doesnt it work????

Member Avatar
pixelsoul
Posting Shark
920 posts since Feb 2011
Reputation Points: 174 [?]
Q&As Helped to Solve: 147 [?]
Skill Endorsements: 25 [?]
 
0
 

You should be using one "=" to set a variable. Using double "==" is for comparison, like using in an IF statement to check if x == this.

var x = document.getElementById('input1').value;

Not really sure what you're doing with document.write(x); either.

Member Avatar
AndrisP
Junior Poster in Training
56 posts since May 2013
Reputation Points: -2 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 1 [?]
 
0
 

in line 11 <input type="submit" onClick="runMe"> change to <input type="submit" onclick="runMe()" />

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article