javascript - Pass js variable to form action url -
I'm not sure whether this is possible, or if I am doing wrong?
I have a form that has been submitted, based on input, the user should be sent to the URL.
For example, if users input '2', then the URL books / itemView? Id = 2
Maybe I get the var = id , which takes the search input box data. Is it possible to add this variable to my existing form action? Maybe a more efficient way?
My current code is as follows;
& lt; Form id = "search" action = "& lt; php echo URL;? & Gt; see books / items? Id =" method = "post" & gt; & Lt; Input type = "text" name = "search" id = "demo" /> & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; My JS
$ (document) .ready (function () {var id = $ ('# search'). Val ();} ); JS is quite new so that any help is appreciated.
must be JS
$ ('# search'). At ('submit', function () {var id = $ ('# demo'). Val (); var formAction = $ ('#search') attr ('action'); $ ('#search') Ether ('action', formaction + id);});
Comments
Post a Comment