使用Perl CGI参数从选项中获取名称和值 [英] Get both name and value from option using Perl CGI param

查看:452
本文介绍了使用Perl CGI参数从选项中获取名称和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的HTML代码中,我有

 < option name =PRODUCTSvalue =3> Products< /选项> 

我需要通过我的Perl CGI参数获取服务器端Perl函数中的名称和值。



我只能得到这个值,有没有办法得到这个名字?

解决方案

< option name =PRODUCTSvalue =3>产品< / option>

< option> 元素不会有一个名称属性,所以这是无效的HTML,浏览器将忽略它(除非它可能使其可用于JavaScript)。

表单提交后,浏览器将向服务器发送所选选项的名称以及所选选项的。这是服务器将收到的唯一信息。



如果您想获得'PRODUCTS',那么您需要:


  1. 将其包含在值中: value =3-PRODUCTS然后 my($数字,$ word)= split' - ',$ value

  2. 查找 3 与服务器(例如嵌入脚本中的散列或数据库查询)相关。


In my HTML code I have

<option name="PRODUCTS" value="3">Products</option>

I need get both the name and value values in my server side Perl function through my Perl CGI param.

I can only get the value, is there a way to get the name also?

解决方案

<option name="PRODUCTS" value="3">Products</option>

An <option> element does not have a name attribute, so this is invalid HTML and the browser will ignore it (except that it might make it available to JavaScript).

When the form is submitted, the browser will send to the server the name of the select coupled with the value of the selected option. This is the only information that the server will receive.

If you want to get 'PRODUCTS' then you will need to either:

  1. Include it in the value: value="3-PRODUCTS" and then my ($number, $word) = split '-', $value
  2. Look up the word that 3 is related to on the server (e.g. in a hash embedded in the script, or with a database query).

这篇关于使用Perl CGI参数从选项中获取名称和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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