HTML表单不按预期更改URL [英] HTML form not changing URL as expected
问题描述
我的项目中有一个问题,我无法修复。
我在使用MySQL - PHP和一切工作正常,但是当我尝试使用下面的表格打开 php / consult.php?consult = add
。
< form action =php / consult.php?consult = addmethod =get>
< td> Instruccion SQL:< / td>
< td>
< input type =textname =codecosultrequired />
< / td>
< / form>
我的浏览器不会将URL更改为php / consult.php?consult = add。相反,它只显示php / consult.php,我做错了什么?
感谢您的回答和您的时间,并对我的英语感到抱歉(这不是太好xD)。 解决方案
如果提交了这个 - 你不需要添加查询字符串 - 如果它是< a href =...
那么你需要完整的查询字符串的url:
< form action =php / test.htmmethod =get>
< td> Instruccion SQL:< / td>
< td>
< input type =textname =codecosultrequired />
< / td>
< / form>
< / form>
< / code> pre>
这给我我的网址+ /php/test.htm?codecosult=ghrth&submit=Submit
ghrth
就是我输入的内容。
你用脚本提交它会让查询字符串关闭并让GET方法处理它 - 这里的脚本就在这里。
< script language =javascript> function submit_this(){this.form.submit();}< / script>
< / head>
< body>
< form name =formid =formaction =php / test.htmmethod =GET>
< td> Instruccion SQL:< / td>
< td>
< input type =textname =codecosultid =codecosultrequired />
< / td>
< div onClick =submit_this();>提交< / div>
这给我 my url + test.htm?codecosult = dfthwrth
dfthwrth
是我输入的内容。
这也有效,但< a href =...
的 href
是
<输入类型=输入类型= textname =codecosultonKeyPress =ahreff.href ='php / test.htm?'+ this.value;required />
< a href =#id =ahreff >点击此处< / a>
这可能是有趣的 - 下拉菜单会将其值同样的方式:
下拉菜单菜单不起作用 - 它现在会!
I have a problem in my project that i cant fix yet.
Im working with MySQL - PHP and everything is working OK but when I try to open "php/consult.php?consult=add
" using the form below.
<form action="php/consult.php?consult=add" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
</form>
My browser doesn't change the URL to "php/consult.php?consult=add". Instead it shows only "php/consult.php", what have I done wrong?
Thanks for your answers and your time, and sorry for my english (it isn't too good xD).
解决方案 This works if submitted - you don't need to add the query string - if it were an <a href="...
then you would need the full query string for the url:
<form action="php/test.htm" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
<input type="submit" name="submit" value="Submit" />
</form>
This gives me my url + /php/test.htm?codecosult=ghrth&submit=Submit
ghrth
was what I had typed.
If you are submitting it with a script leave the query string off and let the "GET" method deal with it - script here is in the head.
<script language="javascript">function submit_this(){this.form.submit();}</script>
</head>
<body>
<form name="form" id="form" action="php/test.htm" method="GET">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" id="codecosult" required/>
</td>
<div onClick="submit_this();">Submit</div>
This gives me my url + test.htm?codecosult=dfthwrth
dfthwrth
was what I had typed.
This also works, though the <a href="...
's href
is modified here by the keypress event each time a key is pressed (may not work in all browsers):
<input type="text" name="codecosult" onKeyPress="ahreff.href='php/test.htm?'+this.value;" required/>
<a href="#" id="ahreff">Click Here</a>
This might be of interest - a dropdown will pass its value in the same way:
dropdown menu doesn't function - it will now!
这篇关于HTML表单不按预期更改URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!