如何将多个值附加到HTML格式的单个参数? [英] How to append multiple values to a single parameter in html form?

查看:84
本文介绍了如何将多个值附加到HTML格式的单个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下形式:

 < form action =process.php> 
< input type =checkboxname =option1value =oats> Oats
< input type =checkboxname =option2value =beans> Beans
< input type =hiddenname =parametervalue =a/>
< input type =submitvalue =Submit/>
< / form>

点击URL后,通常会发生以下情况:浏览器重定向到:

  process.php?option1 = oats& option2 = beans& parameter = a 

我如何做到这一点,当点击提交时,所有复选框最终都是参数的一部分,但用逗号隔开?换句话说就是:

  process.php?parameter = a,oats,beans 

如果没有html解决方案,最好的解决方案是使用最少的javascript / jquery / html。

h2_lin>解决方案

如果您想在一个参数中使用多个值,您必须将其命名为 parameter []



fe:

 < form action =process.php> 
< input type =checkboxname =parameter []value =oats> Oats
< input type =checkboxname =parameter []value =beans> Beans
< input type =hiddenname =parameter []value =a/>
< input type =submitvalue =Submit/>
< / form>


Assuming I have the following form:

<form action="process.php">
<input type="checkbox" name="option1" value="oats"> Oats
<input type="checkbox" name="option2" value="beans"> Beans
<input type="hidden" name="parameter" value="a"/>
<input type="submit" value="Submit"/>
</form>

What would normally happen is after clicking on the URL, the browser redirects to:

process.php?option1=oats&option2=beans&parameter=a

How do I make it such that when the submit is clicked all the checkboxes end up as part of the "parameter", but separated by commas? So in other words it would be:

process.php?parameter=a,oats,beans

Best solution with minimal javascript/jquery/html is best if no html solution.

解决方案

If you want several values in one parameter, you have to name it like parameter[]

f.e.:

<form action="process.php">
<input type="checkbox" name="parameter[]" value="oats"> Oats
<input type="checkbox" name="parameter[]" value="beans"> Beans
<input type="hidden" name="parameter[]" value="a"/>
<input type="submit" value="Submit"/>
</form>

这篇关于如何将多个值附加到HTML格式的单个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆