i have a variable $lat and i need it to pass to javascript function show() where $lat is passed to the url through window.location.href. I have searched everything but nothing seems to work. BTW i dont want to use ajax for this. can it be done with other methods? I am using php codeigniter.
2 Answers
Without using Ajax, you can only pass that variable through your view. Imagine the following scenario:
function yourController()
{
$data['lat'] = 'http://google.com';
$this->load->view('yourView/index', $data);
}
<html>
<head>
</head>
<body>
<script>
function show()
{
window.location.href = '<?php echo $lat; ?>';
}
</script>
</body>
</html>
Comments
var lat = '<?php echo $lat;?>';
show(lat);
function show(lat){
location.href = 'something.com?latval='+lat;
}
4 Comments
Prem Bikram Limbu
are you sending url from controller to view and you want to have it in js.
Nabin
Actually i have several other javascript variables which i have passed to a link with window.location.href..... now i need to add this $lat variable as a parameter to that link. $lat variable was passed in current view from controller.
Prem Bikram Limbu
something like these stackoverflow.com/questions/13085388/… . do concat the lat value.
mickmackusa
This answer is missing its educational explanation.
I have searched everything but nothing seems to workwhat did not worked?