简单的 html/javascript
基本上,我有一堆图像,当我单击图像时,它会将图像 ID 发送到 JavaScript 函数,该函数设置一个值,然后在我提交表单时对其进行处理,以便它进入下一页(我可以在 Coldfusion 中查询该值)。
哎呀,忘记了这个问题:基本上,它也没有达到我想要的效果。带有值的变量似乎没有被发送到下一页!
<html>
<head>
<Script type="text/javascript">
function recordClick(imageid)
{
var myfield = document.getElementById("numSend").value = imageid
}
</script>
</head>
<body>
<FORM action="nextPage.cfm" method="post">
<img src="1.png" NAME="image1" onclick="recordClick(1)"
<img src="2.png" NAME="image2" onclick="recordClick(2)"
<img src="3.png" NAME="image3" onclick="recordClick(3)"
<input type="hidden" id="numSend"/>
<input type="submit" value="Done"/>
</FORM>
</body>
</html>
Basically, i have a bunch of images, and when I click on an image it sends the image ID, to a javascript function, that sets a value which is then processed later when I submit the form so that it goes to the next page (where I can query that value in coldfusion).
Oops, forgot the question: Basically, it doesnt do what I want it too. The variable with the values are not being sent to the next page it seems!
<html>
<head>
<Script type="text/javascript">
function recordClick(imageid)
{
var myfield = document.getElementById("numSend").value = imageid
}
</script>
</head>
<body>
<FORM action="nextPage.cfm" method="post">
<img src="1.png" NAME="image1" onclick="recordClick(1)"
<img src="2.png" NAME="image2" onclick="recordClick(2)"
<img src="3.png" NAME="image3" onclick="recordClick(3)"
<input type="hidden" id="numSend"/>
<input type="submit" value="Done"/>
</FORM>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
标签未正确关闭。此外,您的隐藏输入没有
name
属性,因此当您提交表单时,不会向服务器发送任何内容。尝试这样:Your
<img>
tags are not properly closed. Also your hidden input doesn't have aname
attribute so nothing will be sent to the server when you submit the form. Try like this:我发现代码存在一个问题 - 隐藏字段没有名称属性,因此不会发送该值。
但除此之外,不使用 JavaScript,只使用纯 HTML + CSS 也可以实现相同的结果。只要看看这个小提琴: http://jsfiddle.net/VVD3y/
如果你不点击任何图标,您将被重定向到 google。如果您选择其中一个图标并单击“完成”,您将被重定向到带有查询 stackoverflow、google 或 mozilla 的 google。只需更改每个单选按钮的 NAME 属性,然后在 VALUE 属性中输入您的图像 ID。
如果您想发送多个值,只需将单选按钮替换为复选框即可。
I see one problem with the code – the hidden field doesn't have a name attribute, so the value won't be sent.
But apart from that, there is a possibility to achieve the same result without using JavaScript, but only plain HTML + CSS. Just look at this fiddle: http://jsfiddle.net/VVD3y/
if you don't click any icon, you will be just redirected to google. If you select one of the icons and click Done, you will be redirected to google with the query stackoverflow, google or mozilla. Just change the NAME attribute of every radio button, and in VALUE attributes put your image IDs.
If you'd like to send multiple values, just replace the radio buttons with checkboxes.