![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Posts: 7
Rep Power: 0
![]() |
I have recently tried to take up a small calculator making project to better get used to javascript(which I am not skilled in at all). But my buttons don't work....I have poked around with it diffent ways with no luck....can anybody help?
<html>
<head>
<title>Calculator</title>
<script language="text/javascript">
function calculate(display)
{
display.value = eval(display.value);
}
function numpad_clicked(display,num)
{
alert("The function worked");
display.value = num;
}
<noscript>Javascript not supported!</noscript>
</script>
</head>
<body>
<center>
<form name="calcform" id="calcform" onsubmit="calculate(this.display);return false;">
<font size="+1"><b>Calculator</b></font><br>
<table border="1">
<tr>
<td align="center"><b>Clipboard</b></td>
<td align="center"><b>Display</b></td>
<td></td>
</tr>
<tr>
<td><textarea wrap="physical" cols="17" rows="5"></textarea></td>
<td valign="top" align="right" colspan="3">
<input type="text" name="display" id="display" align="right"><br>
<input type="button" value="7" onclick="numpad_clicked(this.display,'7')">
<input type="button" value="8" onclick="numpad_clicked(this.display,'8')">
<input type="button" value="9" onclick="numpad_clicked(this.display,'9')"><br>
<input type="button" value="4" onclick="numpad_clicked(this.display,'4')">
<input type="button" value="5" onclick="numpad_clicked(this.display,'5')">
<input type="button" value="6" onclick="numpad_clicked(this.display,'6')"><br>
<input type="button" value="1" onclick="numpad_clicked(this.display,'1')">
<input type="button" value="2" onclick="numpad_clicked(this.display,'2')">
<input type="button" value="3" onclick="numpad_clicked(this.display,'3')"><br>
<input type="button" value="0" onclick="numpad_clicked(this.display,'0')">
<input type="submit" value="Enter" style="padding:0 10 0 11;">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>Thanks so much in advance, Zane |
|
|
|
|
|
#2 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You say you're programming in Javascript. You prolly oughtta tell the browser that, too.
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2005
Posts: 7
Rep Power: 0
![]() |
Still nothing
As I understand, most browsers interperet the information the same("javascript" "text/javascript"). I have always seen leading standarizing organizations use the "text/javascript" version that I have. Even on the tutorial site: http://www.w3schools.com/js/tryit.as...ame=tryjs_text they used it in there examples such as the one in the link. The thing is that it works that way in my browser just fine. What doesn't work is MY code. Thanks for the reply. If anyone can clear up my problem, it would be very helpful.
Thanks, Zane |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I took your code exactly as it was posted, threw it into Dreamweaver, changed that one line, uploaded it to my site, and it worked. That was with Firefox. I didn't do any cross-browser tests. If you're convinced everything is ichi ban, what can I say?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jul 2005
Posts: 7
Rep Power: 0
![]() |
hmm...I actually found another retarded problem that I did but not listing it as type="" but language instead. Forgive me for this. However, my code still doesn't work for me
. so you just replaced language="text/javascript" with language="javascript"? I tried that too but to no luck. I am using firefox as well. If you have any more suggestions, let me know.Thanks, Zane |
|
|
|
|
|
#6 | |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
Quote:
I'd also take the noscript from out of the script tags. So: </script> <noscript> |
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jul 2005
Posts: 7
Rep Power: 0
![]() |
wow, that worked.....at least I got an alert box to appear, but my text box string is still not setting correctly. If anyone knows why, please let me know.
Thanks a lot, Zane
__________________
はじめまして! わたしはプログラマですよ! |
|
|
|
|
|
#8 | |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|