Page 1 of 1

making $var = $text$var

Posted: Mon Apr 11, 2005 12:44 pm
by Jr
I have a function that takes an 'option' box and makes whatever value is passed in the function the variable for that = 'selected'. For example:

Code: Select all

function bday_day($text)
{
  IF ($text == "")
{ $na = "selected"; }
ELSE
{
  $day$text = "selected";
}

print "<select name='bday_day'>";
  print "<option value='' $na></option>";
  print "<option value='1' $day1>1</option>";
  print "<option value='2' $day2>2</option>";
  print "<option value='3' $day3>3</option>";
  print "<option value='4' $day4>4</option>";
  print "<option value='5' $day5>5</option>";
  print "<option value='6' $day6>6</option>";
  print "<option value='7' $day7>7</option>";
  print "<option value='8' $day8>8</option>";
...so on...

I'm basically just trying to make $dayX = 'selected' but i can't make a variable $day$text = "selected"; is there a way i can get this to work (or a better way i should be doing this?

Thanks,
Jr-

Jcart | If you are going to post code of any kind, please review Posting Code in the Forumsfirst

Posted: Mon Apr 11, 2005 12:58 pm
by Bennettman

Code: Select all

${day.$text} = 'selected';
You'll want to do some validation if it's user input.

Posted: Mon Apr 11, 2005 2:14 pm
by Jr
Hmm... used it like this and it doesn't seem to work.

* * *

Code: Select all

IF ($text == "")
{ $na = "selected"; }
ELSE
{ ${day.$text} = "selected"; }
* * *

Don't really understand why... help?!?


Jcart | If you are going to post code of any kind, please review Posting Code in the Forumsfirst

Posted: Mon Apr 11, 2005 2:20 pm
by Jr
oops... my bad... typed it in wrong (lol). Thanks for the help.

Jr-

Posted: Mon Apr 11, 2005 2:35 pm
by Bennettman
No problem :wink:

Posted: Thu Apr 14, 2005 5:24 pm
by feyd
remember to quote your string literals.