/    Sign up×
Community /Pin to ProfileBookmark

PLZZZZZZ help me "today"

My time is low. plz help me today. what is problem of this java script code?

[CODE]
<script language=”javascript”>
function Operation (Op)
{
var a= document.frm.txt1.value
var b=document.frm.txt2.value
a= 1*a
b= 1*b
if document.frm.txt3.value=’+’ var c= a+b;
else if document.frm.txt3.value=’-‘ var c= abs(a-b);
else if document.frm.txt3.value=’*’ var c= a*b;
else if document.frm.txt3.value=’/’ var c= a/b;
else var c= ‘gomsho baba’;
alert (c);
}
</script>
.
.
.
<body>
<form id=”frm” name=”form1″ method=”post”>
<label>
<input type=”text” name=”txt1″ />
<br />
<br />
</label>
<label>
<input type=”text” name=”txt2″ />
</label>
<p>
<label>
<input type=”text” name=”txt3″ />
</label>
</p>
<p>
<label>
<input type=”button” name=”Button” value=”Button” onclick=”operation()”; />
</label>
</p>
</form>
</body>
[/CODE]

this button and code dont work, where is the problem?

thanks

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 23.2010 — For the beginning correct your if/else statements syntax
<i>
</i>[B]if[COLOR="Blue"]([/COLOR][I][COLOR="SlateGray"]condition[/COLOR][/I][COLOR="Blue"])[/COLOR][COLOR="Blue"]{[/COLOR][COLOR="SlateGray"][I]statement[/I][/COLOR][COLOR="Blue"]}[/COLOR]
else if[COLOR="Blue"]([/COLOR][I][COLOR="SlateGray"]condition[/COLOR][/I][COLOR="Blue"])[/COLOR][COLOR="Blue"]{[/COLOR][COLOR="SlateGray"][I]statement[/I][/COLOR][COLOR="Blue"]}[/COLOR]
else[COLOR="Blue"] {[/COLOR][COLOR="SlateGray"][I]statement[/I][/COLOR][COLOR="Blue"]}[/COLOR][/B]
Copy linkTweet thisAlerts:
@KorNov 23.2010 — second: use the comparison operator not the asigmnment operator when you compare two variables
<i>
</i>if (document.frm.txt3.value[B][COLOR="Blue"]==[/COLOR][/B]'+')
// and so on
Copy linkTweet thisAlerts:
@abbaskhanauthorNov 23.2010 — I modify to this form:
[CODE]<script language="javascript">
[B][COLOR="Red"]function Operation (Op)[/COLOR][/B]
{
var a= document.frm.txt1.value
var b=document.frm.txt2.value
a= 1*a
b= 1*b
if (document.frm.txt3.value=='+') {var c= a+b;}
else if (document.frm.txt3.value=='-') {var c= abs(a-b);}
else if (document.frm.txt3.value=='*') {var c= a*b;}
else if (document.frm.txt3.value=='/') {var c= a/b;}
else {var c= 'gomsho baba';}
alert (c);
}
</script>

.....
<input type="button" name="Button" value="Button" [COLOR="red"][B]onclick="alert(c)";[/B][/COLOR] />
[/CODE]


but It doesn't work again

I doubt to red bolded places, are they truth? ?
Copy linkTweet thisAlerts:
@KorNov 23.2010 — See the blue where your errors were
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script [COLOR="Blue"]type="text/javascript"[/COLOR]&gt;
function Operation[COLOR="Blue"]()[/COLOR]
{
var a= document.frm.txt1.value
var b=document.frm.txt2.value
a= 1*a
b= 1*b
if (document.frm.txt3.value=='+') {var c= a+b;}
else if (document.frm.txt3.value=='-') {var c= abs(a-b);}
else if (document.frm.txt3.value=='*') {var c= a*b;}
else if (document.frm.txt3.value=='/') {var c= a/b;}
else {var c= 'gomsho baba';}
alert (c);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id="frm" [COLOR="Blue"]name="frm"[/COLOR] method="post"&gt;
&lt;label&gt;
&lt;input type="text" name="txt1"&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/label&gt;
&lt;label&gt;
&lt;input type="text" name="txt2"&gt;
&lt;/label&gt;
&lt;p&gt;
&lt;label&gt;
&lt;input type="text" name="txt3"&gt;
&lt;/label&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;label&gt;
&lt;input type="button" name="Button" value="Button" onclick="[COLOR="Blue"]O[/COLOR]peration[COLOR="Blue"]()[/COLOR]"&gt;
&lt;/label&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@abbaskhanauthorNov 23.2010 — thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks thanks


It's working.

??
Copy linkTweet thisAlerts:
@KorNov 23.2010 — The only way you can thank me is to [I]take a look at the code and understand where your errors were[/I] ?
Copy linkTweet thisAlerts:
@sohguanhNov 24.2010 — Take a look at http://code.google.com/closure/compiler/

Google offer a Java application that help to optimize, minimize and even check your Javascript code for you. And if you like it to be done online you can find it at http://closure-compiler.appspot.com

Very cool stuff once again from Google engineers ?
Copy linkTweet thisAlerts:
@abbaskhanauthorNov 24.2010 — thanks, it's very good thing. ? @};-
×

Success!

Help @abbaskhan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...