Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 27th, 2005, 5:36 PM   #1
narroweyes
Newbie
 
narroweyes's Avatar
 
Join Date: Jul 2005
Posts: 7
Rep Power: 0 narroweyes is on a distinguished road
Question Javascript calculator

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
narroweyes is offline   Reply With Quote
Old Jul 27th, 2005, 6:34 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You say you're programming in Javascript. You prolly oughtta tell the browser that, too.
Quote:
<script language="text/javascript">
Deep six that "text/" bidness.
__________________
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
DaWei is offline   Reply With Quote
Old Jul 28th, 2005, 7:37 PM   #3
narroweyes
Newbie
 
narroweyes's Avatar
 
Join Date: Jul 2005
Posts: 7
Rep Power: 0 narroweyes is on a distinguished road
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
narroweyes is offline   Reply With Quote
Old Jul 28th, 2005, 7:56 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jul 28th, 2005, 8:16 PM   #5
narroweyes
Newbie
 
narroweyes's Avatar
 
Join Date: Jul 2005
Posts: 7
Rep Power: 0 narroweyes is on a distinguished road
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
narroweyes is offline   Reply With Quote
Old Jul 29th, 2005, 11:01 AM   #6
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Quote:
Originally Posted by narroweyes
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
Language is deprecated. Try type="text/javascript" instead.

I'd also take the noscript from out of the script tags.
So:
</script>
<noscript>
Eryk is offline   Reply With Quote
Old Jul 29th, 2005, 4:05 PM   #7
narroweyes
Newbie
 
narroweyes's Avatar
 
Join Date: Jul 2005
Posts: 7
Rep Power: 0 narroweyes is on a distinguished road
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
__________________
はじめまして! わたしはプログラマですよ!
narroweyes is offline   Reply With Quote
Old Jul 30th, 2005, 12:46 PM   #8
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Quote:
Originally Posted by narroweyes
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
this.display is improper for the buttons, because it isn't recognizing this as the form. You should set a variable for the display form.
Eryk is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:39 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC