...

View Full Version : why would a numeric variable display and not a string variable



davehaz
05-31-2006, 04:48 AM
howdy,
I have written a very basic script trying to figure out how to pass variables


function sendto(a)
{
alert(a);
}


I am using data originating from a php script, I am calling the function like below


$max = mysql_result( mysql_query("SELECT COUNT(*) FROM coupons WHERE merchant_dotcom LIKE ('$value%') "), 0 ) ;
if($max > '1'){$z = "Coupons";} else {$z = "Coupon";}
echo "<tr><td><a href='$url' onClick='sendto($max)'>$value</a>-$max $z available</td><td>$merchant_desc</td></tr>";


there is of course much more to the php script but the code above will work for my problem. When I call the function using $max a numeric variable such as


echo "<tr><td><a href='$url' onClick='sendto($max)'>$value</a>-$max $z available</td><td>$merchant_desc</td></tr>";

I get an alert box with the value of $max in it. However if I replace $max with any of the variables that are strings such as $z which would be Coupon or Coupons I get nothing, no alert box, nothing.

what am I doing wrong here? In javascript is there a way to differentiate between numeric and string variables?

thanks.

vwphillips
05-31-2006, 09:15 AM
view the rendered HTML to see what is wrong

then correct the PHP

Kor
05-31-2006, 09:59 AM
what am I doing wrong here? In javascript is there a way to differentiate between numeric and string variables?

In javascript strings are quoted
var myVar = 5;//decimal numeric
var myVar='5';//string

There are various methods to parse strings to numeric back and forth. It depends on what you need.

and, of course, as vwphillips said, show us what rendered HTML code looks like (not php)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum