dongqi8863 2011-05-16 09:37
浏览 12
已采纳

使用javascript获取文本字段的值,并将其发布到表单的操作中

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=$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!

  • 写回答

3条回答 默认 最新

  • duanjiwang2927 2011-05-16 09:55
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线