0

Hi all,

I need help in the alert function. I'm using count in php in which if the item is less than or equal to 10,the alert function would pop up. However my code does not work.Below is my code.

Part of the php code:

echo "<td>".$row['COUNT(item)']."</td>";

Javascript code:

<script language="JavaScript" type="text/javascript"> 
if (count('item')<='10')
{
alert('There is less than 10 items.')
}
</script>

Could anyone help to rectify my mistakes above in which I need the alert function to pop up when the item is less than 10.

Thanks.

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Airshow
0
<script type="text/javascript">
var items = <?php echo count('item'); ?>;
if (items <= 10)
{
alert('There is less than 10 items.')
}
</script>

Airshow

0
var items = <?php echo count('item'); ?>;
if (items <= 10)
{
alert('There is less than 10 items.')
}

Airshow

Edited by Airshow: n/a

0

Hi Airshow,

Thanks for your help.Unfortunatley when I tried the codes you suggest, even if the item is less than 10, the alert box would still pop up.

0

Unfortunatley when I tried the codes you suggest, even if the item is less than 10, the alert box would still pop up.

Surely that's what you would expect. The test is if(items <= 10) .

The alert will not appear when items is greater than 10.

If the behaviour appears incorrect, then "View source" in the browser to see what code is actually served. That should tell you what's going on.


Airshow

0

Hi Airshow,

My apologies.There's a typo error in the previous post.Anyway,thanks for your suggestion in viewing the page source.It have help me in identifying the mistakes that I have done for this js.From the page source,i found that the var items is equal to 1 whereas my php code has include get variables before counting the items and hence i need the var items to be dynamic instead of the value 1.
Thanks for your help once again.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.