Pass multiple parameters in url using javascript in PHP Codeigniter
Multiple parameters pass: in Codeigniter web application you can pass single, twice and multiple parameters using JavaScript. You need to store value in a variable and pass variable into another location.
Define a JavaScript function and store value in variable and generate a URL link using base_url and pass all parameters value into the destination like. that’s like
Single parameters pass:
<script type="text/javascript"> function audit_details(){ var user_id=document.getElementById("user_id").value; window.location.href="<?php echo base_url('MyControl/get_details'); ?>?user_id="+user_id +"&pay_year="+pay_year; } </script>
This example pass the single variable value in a Controller function name.
Twice parameters pass:
<script type="text/javascript"> function audit_details(){ var user_id=document.getElementById("user_id").value; var se_data=document.getElementById("date").value; window.location.href="<?php echo base_url('MyControl/get_details'); ?>?user_id="+user_id +"&se_data="+se_data; } </script>
Multiple parameters pass:
<script type="text/javascript"> function audit_details(){ var user_id=document.getElementById("user_id").value; var se_month=document.getElementById("se_month").value; var se_year=document.getElementById("se_year").value; window.location.href="<?php echo base_url('MyControl/get_details'); ?>?user_id="+user_id +"&se_month="+se_month + "&se_year=" +se_year; } </script>
I think this tutorial will be helpful for you, if you want to get data or update data using where clause then some time you need to pass parameters in the other URL or Controller function.
Related posts