get the value of text field using javascript and post it in action of the form
hi i have a PHP page
and i want to take the value of the text field and post it in the action or in the url i want to put the page number in the url i am numbering the pages<form action="<?php echo $_SERVER['PHP_SELF']."?&p开发者_StackOverflow中文版=$pgNumber"; ?>" method="post" name="page" >
Go to page: <input name="productid" type="text" size="3" />
<input name="Go" type="submit" value="Go" onclick="<?php $pgNumber=$_GET['productid']; ?>" />
</form>
but PHP is server side so i should put a javascript function which add "?&p=6" at the end of the url the "p" is the page number
please guys i know nothing about javascript
thanks in advanced!
Have such form tag instead:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="page" onsubmit="this.action += '?p=' + this.elements['productid'].value;">
This will append the value of the textbox to the submitted URL and still preserve the POST method.
You should use something like this:
<form action="<?php echo $_SERVER['PHP_SELF'];?>"; ?>" method="get" name="page" >
Go to page: <input name="p" type="text" size="3" />
<input name="Go" type="submit" value="Go" />
</form>
When you submit the form clicking the "Go" button, the page will be refreshed with the "?p=xxx" appended.
Change your
<form action="<?php echo $_SERVER['PHP_SELF']."?&p=$pgNumber"; ?>" method="post" name="page" >
Go to page: <input name="productid" type="text" size="3" />
<input name="Go" type="submit" value="Go" onclick="<?php $pgNumber=$_GET['productid']; ?>" />
</form>
to
<form action="<?php echo $_SERVER['PHP_SELF']."?&p=$pgNumber"; ?>" method="get" name="page" >
Go to page: <input name="productid" type="text" size="3" />
<input name="Go" type="submit" value="Go" onclick="<?php $pgNumber=$_GET['productid']; ?>" />
</form>
The difference is in the form method attribute. When method type is get, you will get the form elements and values in the URL. Try it out and let know if it works.
精彩评论