jquery - How do I change the action on a form with javascript? -
i use laravel 5.3
my form :
{!! form::open(['route' => 'shop.process','id'=>'my-form']) !!} ... {!! form::close() !!}
if meets conditions, want change action
my condition in javascript :
if (true) { $('#my-form').attr('action', '/shop/detail') return true; }
if condition met, success convert url this:
but, content not display
content page appear when click url , enter
how can solve problem?
if want change content of form youll need load form ajax form area.
assuming /shop/detail form. should this. either using .load(), or .ajax()
if (true) { $('#my-form').attr('action', '/shop/detail'); $('#my-form').load('/shop/detail'); return true; }
or..
if (true) { $('#my-form').attr('action', '/shop/detail') $.ajax({ url:'/shop/detail', success:function(data){ $('#my-form').html(data); } }) return true; }
however, 2 methods above unlikely work, because doubt /shop/detail inner form. entire form. ie . means need replace element. not load data old form.
if (true) { $.ajax({ url:'/shop/detail', success:function(data){ $('#my-form').replacewith(data); return true; } }) }
wiki
Comments
Post a Comment