PDA

View Full Version : Want Radio button to be auto selected


h8ids
04-12-2006, 08:38 PM
Working with dynamic data.
I have a form which submits info from a radio pair and text box. The radio buttons activate and de-activate the text box. (If user picks "Yes" radio button, they are allowed to add additional information.)

Now I want to allow the user to edit the data stored in the database.
I'm able to capture the "Yes / No" response and additional data into text boxes.
But I want the "Yes / No" answer to be presented using radio buttons not a textbox.

Server side code works fine.
Here is what I have so far; the PHP code was added just for reference.


<script>
function enable1(){
if (document.all || document.getElementById){
if (document.form1.test1.disabled==true)
document.form1.test1.disabled=false
else
document.form1.test1.disabled=false
}
}
function disable1(){
if (document.all || document.getElementById){
if (document.form1.test1.disabled==true)
document.form1.test1.disabled=true
else
document.form1.test1.disabled=true
}
}
</script>
<b>4.</b> Lab:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="Yes1"><b>A.)</b> Yes
<input type="radio" name="LaboratoryYesNo" id="Yes1" value="<?php $myrow["LaboratoryYesNo"]?>" onclick="enable1()"></label>
&nbsp;&nbsp;<label for="No1"><b>B.)</b> No
<input checked type="radio" name="LaboratoryYesNo" id="No1" value="<?php $myrow["LaboratoryYesNo"]?>" onclick="disable1()"></label>

felgall
04-12-2006, 10:27 PM
Try this:

<script type="text/javascript">
function enable1(){
document.form1.test1.disabled=false;
}
function disable1(){
document.form1.test1.disabled=true;
}
</script>
<b>4.</b> Lab:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="Yes1"><b>A.)</b> Yes
<input type="radio" name="LaboratoryYesNo" id="Yes1" value="yes" <?php if ($myrow["LaboratoryYesNo"] == 'yes') echo "selected=\"selected\"" ?> onclick="enable1()"></label>
&nbsp;&nbsp;<label for="No1"><b>B.)</b> No
<input checked type="radio" name="LaboratoryYesNo" id="No1" value="no" <?php if ($myrow["LaboratoryYesNo"] == 'no') echo "selected=\"selected\"" ?> onclick="disable1()"></label>

h8ids
04-14-2006, 05:17 PM
felgall,

Thanks, that works.

Now trying to automatically activate the text box if the "Yes" radio button is checked.

This is what I've tried so far.
The text box remains disabled unless the user clicks, the already checked, "Yes" radio button.

<script type="text/javascript">
function enable1(){
document.form1.LabTimes.disabled=false;
}
function disable1(){
document.form1.LabTimes.disabled=true;
}
</script>

//<input type="radio" name="LaboratoryYesNo" id="Yes1" value="yes" <?php if ($myrow["LaboratoryYesNo"] == 'Yes') echo "checked=\"true\"" ?> onclick="enable1()">

//<input type="radio" name="LaboratoryYesNo" id="Yes1" value="yes" <?php if ($myrow["LaboratoryYesNo"] == 'Yes') echo "checked=\"true\"" ?> onselect="enable1()">

<input type="radio" name="LaboratoryYesNo" id="Yes1" value="yes" <?php if ($myrow["LaboratoryYesNo"] == 'Yes') echo "checked=\"true\"" ?> onfocus="enable1()">

<input disabled type="text" style='background-color: lightyellow' maxlength="100" name="LabTimes" size="40" id="LabTimes" value="<?php echo $myrow["LabTimes"]?>">

Kravvitz
04-14-2006, 10:07 PM
IDs should be unique. (http://www.w3.org/TR/html401/struct/global.html#adef-id)

Change
<input disabled type="text"
to
<input type="text" <?php if ($myrow["LaboratoryYesNo"] != 'Yes') echo 'disabled="disabled"'; ?>

h8ids
04-17-2006, 02:49 PM
Kravvitz,

Thanks for the tip.
Now I know PHP can be defined independently from:

VALUE="<?php if ($myrow["LaboratoryYesNo"] != 'Yes') echo 'disabled="disabled"'; ?>"

Learning to think outside of the box and in the <>