[SOLVED]radio button code

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

Post Reply
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

[SOLVED]radio button code

Post by rubberjohn »

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 »

ok ignore the first question - it was just a missing '=' but why can the checked radio button not change?

thanks

rj
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post your new code please.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

but once the default state has been set i should be able to change the preselected radio button to another one, shouldnt I?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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 »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

might be an "invisible" character issue, or something else. Cache likely isn't the culprit.
Post Reply