简体   繁体   English

如果单击了默认以外的单选按钮,则隐藏下拉框

[英]Hiding Drop Down Boxes if Radio Button other than default is Clicked

I swear I'm going to learn more JavaScript... 我发誓要学习更多JavaScript ...

I have this page (which really an include file in another ASP page, but I copied the correct HTML and made it so it'd load by itself for my testing purposes): 我有此页面(实际上是另一个ASP页面中的一个包含文件,但是我复制了正确的HTML并将其制成,因此可以出于测试目的自行加载):

FO Samples FO样品

This is how it should show when they first load it. 这是他们首次加载时应显示的方式。 If they choose one of the other radio buttons, it should HIDE the 2 dropdown boxes. 如果他们选择其他单选按钮之一,则应隐藏2个下拉框。 Using this code (something I found from someone else's question on here), its working. 使用此代码(我从这里其他人的问题中找到的东西)可以正常工作。

<script type="text/javascript">
    function ChangeDropdowns(value) {
        if (value == "0") {
            document.getElementById('SAMPLEDROPDOWN').style.display = 'block';
        } 
        else  {
            document.getElementById('SAMPLEDROPDOWN').style.display = 'none';
        }        
    }
</script>

But I can't figure out how to make it show them again if they go back to the "I wanna pick my own!" 但是,如果他们回到“我要挑选我自己的!”,我无法弄清楚如何使它们再次显示给他们。 radio. 无线电。 The value of SAMPGROUP is the ID from the database of that sample category group. SAMPGROUP的值是该样本类别组的数据库中的ID。 So it won't necessarily be in numerical order, it might skip #'s (if we delete a category or something). 因此它不一定按数字顺序排列,它可能会跳过#(如果我们删除类别或其他内容)。 Basically, it should show the dropdowns if SAMPGROUP = 0 and not if its anything else! 基本上,如果SAMPGROUP = 0,它应该显示下拉列表,否则就显示下拉列表!

I tried changing my code to this (95 being the value of SAMPGROUP for the "Autumm" option), but it doesn't seem to have made a difference. 我尝试将代码更改为此(95是“ Autumm”选项的SAMPGROUP的值),但似乎没有什么不同。

<script type="text/javascript">
    function ChangeDropdowns(value) {
        if (value == "0") {
            document.getElementById('SAMPLEDROPDOWN').style.display = 'block';
        } else if (value == "95") {
        document.getElementById('SAMPLEDROPDOWN').style.display = 'none';
    }
    else  {
        document.getElementById('SAMPLEDROPDOWN').style.display = 'none';
    }        
    }
</script>

Any help would be greatly appreciated!! 任何帮助将不胜感激!!

Mahalo! 玛哈洛!

You may not be passing any value to the parameter "value" on calling the function ChangeDropdowns. 调用函数ChangeDropdowns时,可能不会将任何值传递给参数“ value”。 Please ensure you pass the value like ChangeDropdowns(0) etc.. 请确保您传递的值如ChangeDropdowns(0)等。

You are not setting the "value" in your onchange event, thus it's never equal to 0. Try changing this: 您没有在onchange事件中设置“值”,因此它永远不会等于0。请尝试更改此值:

<input type="radio" name="SAMPGROUP" value="0" OnChange="Javascript:ChangeDropdowns()" checked />

to

<input type="radio" name="SAMPGROUP" value="0" OnChange="Javascript:ChangeDropdowns(0)" checked />

Here is the fiddle . 这是小提琴

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM