Page 1 of 1

[SOLVED]radio button code

Posted: Thu Mar 16, 2006 5:04 pm
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

Posted: Thu Mar 16, 2006 5:06 pm
by rubberjohn
ok ignore the first question - it was just a missing '=' but why can the checked radio button not change?

thanks

rj

Posted: Thu Mar 16, 2006 10:22 pm
by feyd
post your new code please.

Posted: Fri Mar 17, 2006 3:50 am
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

Posted: Fri Mar 17, 2006 8:01 am
by feyd
how do you think it's not able to change? You're settting the default state when the page loads.

Posted: Fri Mar 17, 2006 8:07 am
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?

Posted: Fri Mar 17, 2006 8:20 am
by feyd
nothing you've posted in this thread would say you couldn't.

Posted: Fri Mar 17, 2006 8:50 am
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

Posted: Fri Mar 17, 2006 10:00 am
by feyd
that changes nothing in regard to how the browser will handle the radio buttons posted.

Posted: Fri Mar 17, 2006 10:05 am
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

Posted: Fri Mar 17, 2006 10:07 am
by feyd
might be an "invisible" character issue, or something else. Cache likely isn't the culprit.