开发者

How can I call a new page and add in the value of a form variable

I would like to link to a new page in the format:

/topic/create&qty=4

Right now I have the value (which is the number 4) stored in an field in a form. I tried to put everything in the form with a post but then realized this isn't what I want to do. I just need clicking on a button to go to link to a new page and send the input field value. The reason I want just a link is that later on I will have posts from that form and they will be handled complet开发者_StackOverflow中文版ely differently.

Is this possible? All I know is that

<form action="/adminTopics" method="post">

isn't what I need.


you can not use POST to send data via url, but you can use GET like this: /topic/create?qty=4

EDIT: Clarification

Writing red in the text field and pressing submit on this form...

<form action="/handler.php" method="GET">
    <input type="text" name="color" />
    <input type="submit" />
</form>

will produce identical results on the server side to clicking this link

<a href='/handler.php?color=red'>rum</a>


If the url is /topic/create?qty=4

and it has to be posted, then you can use

<form action="/topic/create" method="post">
<input type="hidden" name="qty" value="4" />
</form>

<a href="#" onclick="document.forms[0].submit(); return false">Send</a>

or

<script>
window.onload=function() {
  document.forms[0].submit();
}
</script>

If you do NOT need POST, then just call the URL which is the same as a GET

<input id="qty" type="hidden" name="qty" value="4" />

<a href="/topic/create"
 onclick="location=this.href+'?qty='+document.getElementById('qty').value; 
 return false">Go</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜