Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,502
    Thanks
    3
    Thanked 500 Times in 487 Posts
    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/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •