www.webdeveloper.com
Results 1 to 3 of 3

Thread: Radio Button value save to database

  1. #1
    Join Date
    Oct 2011
    Posts
    349

    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:

    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:

    Code:
    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:

    Code:
    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(); 
    }
    Code:
    <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

  2. #2
    Join Date
    Apr 2012
    Posts
    34
    It looks like you are trying to use JavaScript to process your form. While that would work to not have the page refresh, you still need server side code in order for your form to write to your database (ie: JavaScript only does what you can see, whereas PHP / .NET perform the actual task of making your website talk to your database). Here's a pretty simple tutorial that I found that should help you understand a bit more. Let me know if it doesn't make sense.

    http://www.homeandlearn.co.uk/php/php4p10.html

  3. #3
    Join Date
    Dec 2011
    Posts
    68
    I think you choose last one Script It will be better forsave data in the database.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles