0

I have a form like this:

<form class="form-horizontal" role="form" method="POST" name="myform" id="myform" action="{{ url('/mypage/') }}">
        {{ csrf_field() }}
<div id="somecontent">
</div>
<div id="abutton">
</div>
</form>

Then some Jquery like this:

 $('#somecontent').html('<select class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');

And then I add a button like this:

button = $('<button type="submit" form="myform" class="btn btn-theme">Send</button>');

$('#abutton').html(button);

And I also change the action dynamically:

 $("#myform").attr("action","/mypage/" + item_id);

Then I got this in the web file:

Route::post('/mypage/{item_id}','mycontroller@do_something');

And then do this in the controller:

public function do_something($item_id,Request $request){
dd($request);
}

But the $request is empty, it does not contain the value selected in the dynamically generated select.

Any ideas why?

4
  • why are you using item_id as parameter, its already in the request. Commented Jun 7, 2017 at 14:13
  • @Sagar they are 2 different things. Commented Jun 7, 2017 at 14:15
  • 1
    you haven't added name attribute of select, add name attribute and see it will populate into $request Commented Jun 7, 2017 at 14:24
  • @PandhiBhaumik Bingo. You may want to post it as answer. Commented Jun 7, 2017 at 14:27

1 Answer 1

1

you haven't added name attribute of select, add name attribute and see it will populate into $request.

Try below code.

 $('#somecontent').html('<select name="select_name" class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.