Suganya Rajasekar
Suganya Rajasekar

Reputation: 684

How to pass the input type hidden values from view to the controller in laravel5

I'm having a data in my view such as

<input name="start" type="hidden" value="1" />
<input name="end" type="hidden" value="2" />

I need to pass this values to the controller when my page getting load.

How should I pass it to the controller.

Is there any way to send this values using jQuery!!!...

Someone help me..

Upvotes: 2

Views: 1271

Answers (2)

Ajay Kulkarni
Ajay Kulkarni

Reputation: 3039

Why don't you try ajax?

<input name="start" class="start" type="hidden" value="some_value1" />
<input name="end" class="end" type="hidden" value="some_value2" />

var postData = {
    "param1" : some_value1,
    "param2" : some_value2
};

console.log(postData);

$.ajax({
    type: "POST",
    url: "test.php",
    data: postData, 
    success: function(){
        alert(param1 + ' ' + param2);
        window.open("test.php"); 
    }
});  

test.php is your controller...

Upvotes: 2

Amir Hossain
Amir Hossain

Reputation: 693

Try this

<input name="start" class="start" type="hidden" value="1" />
<input name="end" class="end" type="hidden" value="2" />

<script type="text/javascript">
   $(function() {
    pass_value();  
   });


function pass_value(){
   var start = $(".start").val();
   var end = $(".end").val();
   $.post('{your_url}', {start:start, end:end},function(data){
     console.log(data);
  })
}

</script>

Upvotes: 1

Related Questions