Jump to content

Get new value of selected Radio Box


tmv105

Recommended Posts

I have checked the appropriate radio box from my database value, but now I need to be able to retrieve the edited choice to update my database. Here is the code:

 

<?php $db_maritalstatus = $row_rsAdvancedPlan['maritalstatus']; ?>

 

<input name="maritalstatus" id="maritalstatus" value="single"<?php if ($db_maritalstatus == "single") {echo 'checked=\"checked\"';} ?> type="radio" /> <label for="single" class="smaller">Single</label>

 

<input name="maritalstatus" id="maritalstatus" value="married"<?php if ($db_maritalstatus == "married") {echo 'checked=\"checked\"';} ?> type="radio" /> <label for="married" class="smaller">Married</label>

 

<input name="maritalstatus" id="maritalstatus" value="widowed"<?php if ($db_maritalstatus == "widowed") {echo 'checked=\"checked\"';} ?> type="radio" /> <label for="widowed" class="smaller">Widowed</label>       

 

<input name="maritalstatus" id="maritalstatus" value="divorced"<?php if ($db_maritalstatus == "divorced") {echo 'checked=\"checked\"';} ?> type="radio" /><label for="divorced" class="smaller">Divorced</label>

When I select a new valuewhile editing form,my retrieval still holds the original value which loaded upon populating.

Link to comment
https://forums.phpfreaks.com/topic/165177-get-new-value-of-selected-radio-box/
Share on other sites

Your escaping double quotes unnecessarily, and have left out the space between the value and checked.

 

<input name="maritalstatus" id="maritalstatus" value="single"<?php if ($db_maritalstatus == "single") {echo ' checked="checked"';} ?> type="radio" /> <label for="single" class="smaller">Single</label>

 

ps; This could also be written as....

 

<input name="maritalstatus" id="maritalstatus" value="single"<?php echo ($db_maritalstatus == "single") ? ' checked="checked"' : '' ?> type="radio" /> <label for="single" class="smaller">Single</label>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.