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.

Recommended Answers

All 6 Replies

<script type="text/javascript">
var items = <?php echo count('item'); ?>;
if (items <= 10)
{
alert('There is less than 10 items.')
}
</script>

Airshow

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

Airshow

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.

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

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.

:cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.