If statement: != does not work

W

weblinkunlimited

Hello,

Can someone help me.
'number' is a string and not a number!
Why does the following not work:

<script type='text/javascript'>

function calculate(rij) {

var number = "0";

if(number!="0") {
for(var i=0; i<description.length; i++) {
if(description == descr) {
var arrrow=i;
}
}
)
}
</script>

I also tried:
if(number>"0") {

But because number is a string, that did not help much (you have to
try sometimes a few things).
The above source-code is part of a PHP-script (I replace the \" in "),
but that should not matter.
When the PHP-code has been started, I see an error in my IE at the
left bottom of the window (Error on page / Done). When I run the above
script only, I do not get an error. But when I add a line
alert("test"); before </script>, I do not see the alert, that alerts
me that there is an error.

I hope you have enough information to see what i did wrong.

Thank you in advance!
 
E

Evertjan.

wrote on 12 mrt 2008 in comp.lang.javascript:
Why does the following not work:

<script type='text/javascript'>

function calculate(rij) {

var number = "0";

if(number!="0") {
for(var i=0; i<description.length; i++) {
if(description == descr) {
var arrrow=i;
}
}
)


The ) must be a }

Please do not just say "does not work",
but state the error line and code.

}
</script>
The above source-code is part of a PHP-script

It is not, it is plain clientside javascript.
(I replace the \" in "),
??

but that should not matter.
When the PHP-code has been started,

The PHP code, should have been finished by then,
because that runs on the server and just manipulates
the html stream sent to the client.

So please look at and perhaps send us [part of] the view source code
that the browser received. The code as submitted to the PHP engine on the
browser is not of interest to us in this NG, and your error is
clientside.
I see an error in my IE at the
left bottom of the window (Error on page / Done).

What browser?

If it is IE you shoud double click the error icon to read the error
When I run the above
script only, I do not get an error.

Compare both view source codes.
 
D

dave

Hello,

Can someone help me.
'number' is a string and not a number!
Why does the following not work:

<script type='text/javascript'>

function calculate(rij) {

var number = "0";

if(number!="0") {
for(var i=0; i<description.length; i++) {
if(description == descr) {
var arrrow=i;
}
}
)
}
</script>

I also tried:
if(number>"0") {

But because number is a string, that did not help much (you have to
try sometimes a few things).
The above source-code is part of a PHP-script (I replace the \" in "),
but that should not matter.
When the PHP-code has been started, I see an error in my IE at the
left bottom of the window (Error on page / Done). When I run the above
script only, I do not get an error. But when I add a line
alert("test"); before </script>, I do not see the alert, that alerts
me that there is an error.

I hope you have enough information to see what i did wrong.

Thank you in advance!


I'll give you a hint, run the code in Firefox and look at the
javascript error log. That will help you find the error.
 
R

RobG

Hello,

Can someone help me.
'number' is a string and not a number!
Why does the following not work:

<script type='text/javascript'>

function calculate(rij) {

var number = "0";

if(number!="0") {

It seems to me that will always return false and the block statement
will never be executed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top