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条)

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏