Jump to content

Radio Button value save to database


newphpcoder

Recommended Posts

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

 

 

Link to comment
Share on other sites

Thank you..

 

 

 

I resolved it using this code:

 

 

 


function ApproveLeaveOP(){
if(document.getElementById('H').checked) {
    var CHK_LEAVE = document.getElementById('H').value;
      }
else if(document.getElementById('W').checked) { 
      var CHK_LEAVE = document.getElementById('W').value;
      }
   
    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+"&CHK_LEAVE="+CHK_LEAVE;
    //document.sampleform.action="AddLeave.php";
   //document.sampleform.action="AddLeave.php?APPROVE="+APPROVE";
    document.sampleform.submit();
   

   

}



 

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.