Jump to content

Archived

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

nissa

is there a better way to set radio buttons checked from value in DB?

Recommended Posts

Hello,

I am new to web development and I'm trying to set which radio button is checked from my DB. I have it set up so that it works but it seems kinda sloppy code to me. I can't seem to find anything that will tell me how to set the radio to checked from the DB. I'm using Ajax to save and it works fine. Is there a better way to do this without the repetition of code? (renewalrequest is set as number(1) in the table)

Edit: actually it doesn't work - the values are the same for all radios of the same name

[code]
<?php
        $statement = OCIParse($dbConnect, "select renewalrequest from rip_project_details where rip=".$ripid);
        OCIExecute($statement);
                  if (OCIFetchInto($statement, $row)) {
    if($row[0] == 0){
?>
<tr><td><input type="radio" name="renewalrequest" [color=red]checked[/color] value="0" id="servicerenewal" onclick="ischanged(this); setChanged()"><label for="servicerenewal">Managed Service Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="1" id="softwarerenewal" onclick="ischanged(this); setChanged()"><label for="softwarerenewal">Software Maintenance Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="2" id="serverrefresh" onclick="ischanged(this); setChanged()"><label for="serverrefresh">Server Refresh ONLY?</label></td>
</tr>
          <?php
     } else if ($row[0] == 1){
    ?>
<tr><td><input type="radio" name="renewalrequest" value="0" id="servicerenewal" onclick="ischanged(this); setChanged()"><label for="servicerenewal">Managed Service Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" [color=red]checked[/color] value="1" id="softwarerenewal" onclick="ischanged(this); setChanged()"><label for="softwarerenewal">Software Maintenance Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="2" id="serverrefresh" onclick="ischanged(this); setChanged()"><label for="serverrefresh">Server Refresh ONLY?</label></td>
</tr>
          <?php
    } else {
?>
<tr><td><input type="radio" name="renewalrequest" value="0" id="servicerenewal" onclick="ischanged(this); setChanged()"><label for="servicerenewal">Managed Service Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="1" id="softwarerenewal" onclick="ischanged(this); setChanged()"><label for="softwarerenewal">Software Maintenance Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" [color=red]checked[/color] value="2" id="serverrefresh" onclick="ischanged(this); setChanged()"><label for="serverrefresh">Server Refresh ONLY?</label></td>
</tr>
   <?php
              } //end inner if
   } else {
    ?>
<tr><td><input type="radio" name="renewalrequest" value="0" id="servicerenewal" onclick="ischanged(this); setChanged()"><label for="servicerenewal">Managed Service Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="1" id="softwarerenewal" onclick="ischanged(this); setChanged()"><label for="softwarerenewal">Software Maintenance Renewal?</label></td>
</tr>
<tr><td><input type="radio" name="renewalrequest" value="2" id="serverrefresh" onclick="ischanged(this); setChanged()"><label for="serverrefresh">Server Refresh ONLY?</label></td>
</tr>
          <?php
          }
          ocifreestatement($statement);
          ?>
[/code]

Thanks in advance!

Nissa

Share this post


Link to post
Share on other sites

×

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.