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
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Thu Mar 16, 2006 5:04 pm
From what I have seen, the code to preselect radio buttons is something like this:
Code: Select all
<input type="radio" name="status" value="active" <?php if($get_status['status'] = "active"){echo 'checked = "checked"';} ?> />
Active
<input type="radio" name="status" value="inactive" <?php if($get_status['status'] = "inactive"){echo 'checked = "checked"';} ?> />
Inactive
<input type="radio" name="status" value="complete" <?php if($get_status['status'] = "complete"){echo 'checked = "checked"';} ?> />
Complete
<input name="Update" type="submit" id="Update" value="Update" />
But two things don't seem to work. When the page first loads the wrong radio button is check and when you click on it or any of the other buttons the correct button becomes checked.
Secondly once they are checked you can't change selection to another radio button.
Can someone tell me where I am going wrong?
Thanks
rj
Last edited by
rubberjohn on Fri Mar 17, 2006 9:47 am, edited 1 time in total.
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Thu Mar 16, 2006 5:06 pm
ok ignore the first question - it was just a missing '=' but why can the checked radio button not change?
thanks
rj
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Mar 16, 2006 10:22 pm
post your new code please.
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Fri Mar 17, 2006 3:50 am
ok here it is...
Code: Select all
<input type="radio" name="job_status" value="active" <?php if($get_job['job_status'] == "active"){echo 'checked = "checked"';} ?> />
Active
<input type="radio" name="job_status" value="inactive" <?php if($get_job['job_status'] == "inactive"){echo 'checked = "checked"';} ?> />
Inactive
<input type="radio" name="job_status" value="complete" <?php if($get_job['job_status'] == "complete"){echo 'checked = "checked"';} ?> />
Complete
<input name="Update" type="submit" id="Update" value="Update" />
thanks
rj
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 17, 2006 8:01 am
how do you think it's not able to change? You're settting the default state when the page loads.
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Fri Mar 17, 2006 8:07 am
but once the default state has been set i should be able to change the preselected radio button to another one, shouldnt I?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 17, 2006 8:20 am
nothing you've posted in this thread would say you couldn't.
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Fri Mar 17, 2006 8:50 am
It shouldn't do but does it matter that the array thats being tested is the result fo an sql query that has fetched the value of the radio button from a db
OR
that there are two forms on the page?
cheers
rj
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 17, 2006 10:00 am
that changes nothing in regard to how the browser will handle the radio buttons posted.
rubberjohn
Forum Contributor
Posts: 193 Joined: Fri Feb 25, 2005 4:03 am
Post
by rubberjohn » Fri Mar 17, 2006 10:05 am
i put solved in the title cos i didnt want to bump it back up to the top - i cant explain it but i just deleted the radio buttons and did them again and it works, and the code is identical - maybe a caching issue??
cheers
rj
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Mar 17, 2006 10:07 am
might be an "invisible" character issue, or something else. Cache likely isn't the culprit.