Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-31-2006, 03:48 AM   PM User | #1
davehaz
Regular Coder

 
Join Date: Apr 2005
Posts: 388
Thanks: 0
Thanked 0 Times in 0 Posts
davehaz is an unknown quantity at this point
why would a numeric variable display and not a string variable

howdy,
I have written a very basic script trying to figure out how to pass variables
Code:
function sendto(a)
{
alert(a);
}
I am using data originating from a php script, I am calling the function like below
Code:
$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
Code:
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.
davehaz is offline   Reply With Quote
Old 05-31-2006, 08:15 AM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,356
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
view the rendered HTML to see what is wrong

then correct the PHP
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 05-31-2006, 08:59 AM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
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)
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:48 AM.


Advertisement
Log in to turn off these ads.