表单的Javascript问题 [英] Javascript Problem with Form

查看:46
本文介绍了表单的Javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是javascript的新手,所以我可以使用你的帮助。我检查了常见问题解答并搜索了谷歌

但我无法解决这个问题。


我的表格如下:


< form action =" serversidehandlerurl.php"方法= QUOT;交" onsubmit =" if(document.getelementbyid){

window.open(document.getelementbyid(''pblinks'')。sel ectedindex.value);返回false; }" >

< select id =" pblinks"大小= QUOT 1 QUOT; >

< option selected =" selected" >选择尺寸...< / option>

< optgroup label =" Containers">

< option value =" url / 1" ; > 1.0 L - $ 19.90< / option>

< option value =" url / 2" > 1.5 L - $ 29.85< / option>

< option value =" url / 3" > 2.0 L - $ 39.80< / option>

< option value =" url / 4" > 3.0 L - $ 59.70< / option>

< / optgroup>

< / select>< br />

< input type =" submit" value ="立即购买/>

< / form>


现在不要说这是一个严格的XHTML网站和我无法更改为Transitional因此

属性名称必须小写。这意味着在HTML标记中使用属性名称的部分资本化的典型JavaScript实践必须遵循。因此,在标签onLoad变为onload,onClick变为

onclick等等。这个改变不应该破坏任何东西。


另请注意,在Strict中,某些元素是不允许的。例如,表单元素可能没有

name =属性,这使得很难通过常规方式引用。解决方法是给你想要引用id =属性的
元素,然后使用JavaScript getElementByID()函数

来引用它们。表单本身不需要id属性,只需要你想要引用的元素

to。


当我运行这个表单时,我接受了这个动作serversidehandlerurl.php网站,但选项网址是

未选中。 window.open命令也不起作用(即,新窗口无法打开)。


就像我说我是javascript的新手,任何帮助表示赞赏。提前致谢...


Tom

Hi all, I am a newbe to javascript so I could use your help. I checked the FAQs and searched google
but I could not resolve this problem.

My form is as follows:

<form action="serversidehandlerurl.php" method="post" onsubmit="if(document.getelementbyid) {
window.open(document.getelementbyid(''pblinks'').sel ectedindex.value); return false; }" >
<select id="pblinks" size="1" >
<option selected="selected" >Select the size...</option>
<optgroup label="Containers">
<option value="url/1" >1.0 L - $19.90</option>
<option value="url/2" >1.5 L - $29.85</option>
<option value="url/3" >2.0 L - $39.80</option>
<option value="url/4" >3.0 L - $59.70</option>
</optgroup>
</select ><br />
<input type="submit" value="Buy Now" / >
</form >

Now don''t flip out this is a "Strict" XHTML site and I cannot change to "Transitional" therefore
Attribute names must be lower-case. This means that the typical JavaScript practice of capitalizing
parts of attribute names in HTML tags must go. So within tags onLoad becomes onload, onClick becomes
onclick and so on. This change should not break anything.

Also note that in Strict some elements are not allowed. For example, a form element may not have a
name= attribute, which makes it difficult to refer to by normal means. The workaround is to give
elements you want to refer to an id= attribute and then use the JavaScript getElementByID() function
to refer to them. The form itself does not need an id attribute, only the element you want to refer
to.

When I run this form I am taken to the action serversidehandlerurl.php site but the option url is
not selected. Also the window.open command does not function (i.e., a new window does not open).

Like I said I am a newbe to javascript and any help is appreciated. Thanks in advance...

Tom

推荐答案

19.90< / option>

< option value =" url / 2" > 1.5 L -
19.90</option>
<option value="url/2" >1.5 L -


29.85< / option>

< option value =" url / 3" > 2.0 L -
29.85</option>
<option value="url/3" >2.0 L -


39.80< / option>

< option value =" url / 4" > 3.0 L -
39.80</option>
<option value="url/4" >3.0 L -


这篇关于表单的Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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