简体   繁体   中英

How to copy the hidden field value and pass it on another page using jquery in CodeIgniter?

I am new with CodeIgniter and I want to pass hidden field value to another page using jQuery in CodeIgniter. Can I do this using jQuery?

<input type="hidden" name="grdtot" class="grdtot" />

this hidden field on cart.php page

  <label id="grdtot_c" name="grdtot_c" class="grdtot_c"></label>

I want to fetch this hidden field value on checkout.php page. How I can do this using jQuery?

You can do this another way using localstorage to getting value from another page

Just write like this on page one.

localStorage.setItem('Gridtotal', $('.grdtot').val());

And get value from another page.

var grdTotal= localStorage.getItem('Gridtotal');
$('#grdtot_c').val(grdTotal);

Suppose You have form given below:

<body>
    <div>Upload data to the server without page Refresh</div>
    <input type="hidden" name="hidden_name" id="hidden_name">
    <input type="text" name="name" id="name">
    <input type="text" name="email" id="email">
    <input type="text" name="website" id="website">
    <input type="submit" name="submit" id="save" value="Submit">

    <div id="display"></div>
</body>

And Now Your Script to send data to Your Controller . You must have to use ajax to send data to the controller in CodeIgniter, And It will make your work easy.

<script>
$(document).ready(function(){
    $('#save').click(function(){
        var hidden_name = $('#hidden_name').val();
        var name = $('#name').val();
        var email = $('#email').val();
        var website = $('#website').val();

        $.ajax({
            type:'POST',
            url:'<?php echo base_url();?>index.php/controller_name/function_name',
            async:false,
            data:{
                "done":1,
                "hidden_name":hidden_name,
                "name":name,
                "email":email,
                "website":website   
                },
            success:function(data){
                $('#display').html(data);
            }   
        });
    });
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM