Hi, This is probably a stupid question but I don't know much of these languages. I have a variable named "myname" I want to check if the variable is empty . If yes then I have to write the following: var myname= "jeet"; If no then do nothing . What will be the code for this ? Actually a function is sending a value to this variable but if the value is an empty string then I want to have "jeet" in it . Thank you jeet
if (! myname) { myname="jeet"; } Code (markup): That ought to work if the variable truly contains a null value. cheers, gary
Hi, That's not working ... I think there is another bug in the script I am writing. I might not be able to do this using javascript. Later in the code I am putting this value in a PHP variable named $myn but that's not empty. It's something like this : $myn= "my name is ".$c; So here's what I tried . code: <?php $m = "my name is "; // comparing $myn to $m if $myn = $m { $myn= "myname is jeet"; } ?> But that keeps giving me a parssing error. I am checking if the value of $myn is the same as $m and if yes then $myn is set to a complete string specified by me else nothing is done. Can you suggest something here also? Thank you jeet
For one thing, if $myn = $m would always evaluate as true if you had remembered the (). Do, if ($myn == $m). In this case, you should do two tests; if (empty($myn)) { echo "Houston, we have a problem."; } else if ($myn == $m) { $myn = $m . " Jeet"; } Code (markup): Why not test $c? cheers, gary
Excellent Brilliant Superb!!! Very cool ! I was struggling with this since last evening . It's been like 24 hours now... Thank you a million times for the help! Best regards jeet