Jump to content

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.