PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Jr
Forum Commoner
Posts: 99 Joined: Mon Mar 07, 2005 3:25 pm
Post
by Jr » Mon Apr 11, 2005 12:44 pm
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 Forums first
Bennettman
Forum Contributor
Posts: 130 Joined: Sat Jun 15, 2002 3:58 pm
Post
by Bennettman » Mon Apr 11, 2005 12:58 pm
You'll want to do some validation if it's user input.
Jr
Forum Commoner
Posts: 99 Joined: Mon Mar 07, 2005 3:25 pm
Post
by Jr » Mon Apr 11, 2005 2:14 pm
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 Forums first
Jr
Forum Commoner
Posts: 99 Joined: Mon Mar 07, 2005 3:25 pm
Post
by Jr » Mon Apr 11, 2005 2:20 pm
oops... my bad... typed it in wrong (lol). Thanks for the help.
Jr-
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Apr 14, 2005 5:24 pm
remember to quote your string literals.