Radio Button value save to database

Hi…

I’m new in radio button.

Now I have to radio button one for H value means half and W for Whole.

Now I don’t know how can I get the value to save in to my database.

here is my code:


<input type="radio" name="CHK_LEAVE" id="H" value="H">
<input type="radio" name="CHK_LEAVE" id="W"value="W">
<script>
function ApproveLeaveOP(){
    var CHK_LEAVE = document.getElementByName('CHK_LEAVE').value;

    alert (CHK_LEAVE);
}
</script>

I got an error Object Required.

I tried this test:


function chk(){
      if(document.getElementById('H').checked) {
         alert ('H')
      }else if(document.getElementById('W').checked) {
       alert ('W')
      }
}

And it works.

Now How can I save it to my database

I have this code and I need to insert here the code to get the value of radio button that I choose:


function ApproveLeaveOP(){
var EMP_NO = document.getElementById('EMP_NO').value;
    var DATE_LEAVE_FROM = document.getElementById('DATE_LEAVE_FROM').value;
    var DATE_LEAVE_TO = document.getElementById('DATE_LEAVE_TO').value;
    var NAME = document.getElementById('NAME').value;
    var HOURS_LEAVE = document.getElementById('HOURS_LEAVE').value;
    var Approve = document.getElementById('Approve').value;
    var TYPE = document.getElementById('TYPE').value;
    var dateprocess = document.getElementById('dateprocess').value;

    document.sampleform.action="AddLeave.php?EMP_NO="+EMP_NO+"&DATE_LEAVE_FROM="+DATE_LEAVE_FROM+"&DATE_LEAVE_TO="+DATE_LEAVE_TO+"&NAME="+NAME+"&HOURS_LEAVE="+HOURS_LEAVE+"&Approve="+Approve+"&TYPE="+TYPE+"&dateprocess="+dateprocess;
       document.sampleform.submit();
}


<input type="text" name="EMP_NO" id="EMP_NO" value="{$empno}" size="8" style="background: #e2e2e2" readonly="readonly">
<input type="text" name="NAME" id="NAME" value="{$fullname}" size="35" style="background: #e2e2e2" readonly="readonly">
<input type="text" name="DATE_LEAVE_FROM" id="DATE_LEAVE_FROM" value="{$DATE_LEAVE_FROM}" size="9">
<input type="text" name="DATE_LEAVE_TO" id="DATE_LEAVE_TO" value="{$DATE_LEAVE_TO}" size="9">

{html_options id=TYPE name=TYPE options=$LeaveStatus selected=$TYPE style="width:140px;"}
<input type="radio" name="CHK_LEAVE" id="H" value="H">
<input type="radio" name="CHK_LEAVE" id="W"value="W">
<!--<input type="text" name="STATUS" id="STATUS" value="{$STATUS}" size="10">-->
<input type="button" name="Approve" value="Approve" id="Approve" onclick="ApproveLeaveOP()">

I need to save in to my database what I choose.

Thank you

This occurs because there is more than one element with the same name, so getElementsByName returns you with an array-like item list, instead of a single element.

Normally the best way to handle what you’re doing here is to submit the form to a server-side page, so that only the selected values are submitted through to the server, from where the form can be processed using server-side code.

What do you want to create? JS validation the form? Serverside validation with AJAX call? Or just submit form and insert data into database?