Is there a way to display a specific dropdown menu depending on the checkbox that is selected?

I have a bunch of checkbox items, including one labeled nocalls, as well as a couple of dropdownlist boxes.

Here are the dropdown boxes:

<tr>
    <td align="right"><FONT class="Arial10"><B>Profile<font color="#ff0000">*</font></B></FONT></td>
    <td>
        <asp:dropdownlist id="eProfile" runat="server" Width="144px">
            <asp:listitem Value="" Selected="True">--Select A Profile--</asp:listitem>
            <asp:listitem Value="Add Profile">Add Profile</asp:listitem>
            <asp:listitem Value="Delete Profile">Delete Profile</asp:listitem>
            <asp:listitem Value="Update Profile">Update Profile</asp:listitem>
            <asp:listitem Value="Transfer">Transfer</asp:listitem>
            <asp:listitem Value="See Notes">See Notes</asp:listitem>
        </asp:dropdownlist>
    </td>
</tr>
<TR>
    <td align="right"><FONT class="Arial10"><B>Profile<font color="#ff0000">*</font></B></FONT></td>
    <td>
        <asp:dropdownlist id="kProfile" runat="server" Width="144px">
            <asp:listitem Value="" Selected="True">--Select A Profile--</asp:listitem>
            <asp:listitem Value="Add Manager Profile">Add Manager Profile</asp:listitem>
            <asp:listitem Value="Add User Profile">Add User Profile</asp:listitem>
        </asp:dropdownlist>
    </td>
</TR>

And here is the list of checkboxes:

<input id="CheckBox9" runat="server" type="checkbox" value="Notary" />Notary
<input id="CheckBox10" runat="server" type="checkbox" value="VPN"  />VPN
<input id="CheckBox11" runat="server" type="checkbox" value="VPSPagecenter"  />VPS-Pagecenter
<input id="CheckBox12" runat="server" type="checkbox" value="PCDOC"  />PC DOC
<input id="CheckBox13" runat="server" type="checkbox" value="nocalls" />nocalls

If the user checks the nocalls checkbox, we want to display only the kProfile dropdown and hide the eProfile dropdown.

If the user clicks on any other checkboxes except for nocalls, the kProfile dropdown should be hidden while the eProfile dropdown is displayed.

I attempted to use JavaScript to achieve this but I'm still seeing both dropdowns.

I must be making a silly mistake somewhere.

if (theForm.service.value.indexOf("nocalls") >= 0) {

    var kprofobj = document.getElementById("kProfile");
    var eprofobj = document.getElementById("eProfile");

    kprofobj.style.visiblilty = "visible";
    eprofobj.style.visiblilty = "hidden";
    kprofobj.style.display = "block";

}

<script type="text/javascript"> 
$(document).ready(function () {
    if ($('#nocalls').attr('checked')) { 
        $('#eProfile').hide(); 
        $('#kProfile').show() 
    }; 
});
</script>

Answer №1

When dealing with a checkbox, it is important to check for the CHECKED attribute rather than the value.

if (theForm.service.checked)

Remember:

if (theForm.service.value.indexOf("nocalls") >= 0) 

By the way, table-based layouts and inline styling should be avoided.

Additionally, .NET includes jQuery which allows for simplified $('#kProfile').hide()/$('#kProfile').show() functions without the need for extra JS code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What methods can I utilize to prevent pop-up errors from appearing in my javascript code?

Recently, I've been working on utilizing an innovative IBM tool called Presto that efficiently transforms traditional green screens into browser-based pages. While the process is effective, it involves some quirky behaviors. One particular challenge I ...

Is there a way to send a non-JSON value to an angular.js http.post function?

Struggling to send two parameters using the HTTP POST method in Angular.js. Here is the code I have implemented: Controller var installerApp = angular.module('installerApp', []); installerApp.controller('InstallerCntlr',function($scop ...

Set up Node to utilize Object.assign

Currently, I am experimenting with Object.assign functionality in IO.js and Node.JS, but encountering an unexpected error. /Users/lp/.nvm/versions/io.js/v2.4.0/bin/iojs --debug-brk=59842 --nolazy mixin.js Debugger listening on port 59842 /Users/lp/Documen ...

Executing Node.js Function from an External File Dynamically

Is it possible to run a Node function from an external file that may be subject to change? main.js function read_external(){ var external = require('./external.js'); var result = external.result(); console.log(result); } setInterva ...

Transforming the output of a PHP script from an HTML table into an ion-list format tailored for the Ionic framework

Currently I am working on an application built with the Ionic framework. I have developed a PHP file to retrieve 'Users' data from my database and it is currently being displayed in an HTML table format. In the services section of the framework, ...

What is the best way to zoom in on an image and make it move off the screen as I scroll through my webpage?

I am working on a website design where I would like to implement an image zoom effect as the user scrolls down. Additionally, I want the image to move to either the left or right side of the screen as it goes out of view when scrolling to the bottom. While ...

Placing an exit button beside an image for easy navigation

Here is a snippet of my code: <style type="text/css"> .containerdiv { position:relative;width:100%;display:inline-block;} .image1 { position: absolute; top: 20px; left: 10px; } </style> <div class="containerdiv"> <ima ...

The magnitude of each new keystroke is squared compared to its predecessor

exploring the relationship between keyboard and console inputs Each subsequent e.key entry is occurring twice as frequently as the previous one. Once it reaches 8-9 characters, the rendering frequency skyrockets to over 1000 times per character. Here&apos ...

Turn off automatic spelling correction and predictive text in a content-editable section

I'm currently working on a cross-browser application using Script#. I've incorporated a contenteditable div where users can input text. However, I am facing an issue with the auto correct/auto completion feature altering the user's text. Co ...

Dealing with repeated parameters in a URLHow can you handle duplicate

My Ajax select input dynamically changes the URL without refreshing the page. However, I have encountered an issue where repeated parameters stack in the URL when the select input is changed multiple times: [domain]/find.php?cat=1#pricemin=10&pricem ...

Converting units to rem dynamically in CSS: a comprehensive guide

Hey there, I'm currently trying to dynamically convert units into rem in CSS and facing some issues. I have set the root font-size as 23px The current font-size is 16px The expected result should be 16 / 23 => 0.695rem Question: I am looking for ...

ExpressJS Node - .get switch to .route utilizing connect-ensure-login middleware

Considering that I have initially written a route using app.route: app.route('/word/:id') .get(word.getWord) .put(word.updateWord) .delete(word.deleteWord); Now, my aim is to modify the route by adding some middleware. While I am aw ...

Tips on including variables within quotation marks in JavaScript

I'm currently working on a JavaScript project using Pug. My goal is to use Express and MongoDB to develop a CRUD application that generates an edit button for each post, triggering a specific event when clicked. However, instead of the desired resul ...

Unexpected Issues with the Ant Design Sidebar Layout Demo

My React webapp is utilizing the Ant design component framework version 4. I attempted to integrate this example from the Antd documentation into my webapp: https://codesandbox.io/s/ymspt However, when I implemented the code in my webapp, the result didn ...

Unable to display search results with AJAX in Select2

I'm struggling with getting the desired outcomes to display in Select2 when using AJAX. Below is my code: $(document).ready(function() { $("#producto").select2({ placeholder: 'Select a product', formatResult: productForm ...

What sets apart the $ and $() functions in jQuery?

After reviewing the jQuery API, I noticed that $() represents a collection of matched elements. However, I am curious about the significance of $. An example from the imagesLoaded library is provided below. if ( $ ) { $.fn.imagesLoaded = function( opt ...

Struggling to design a responsive layout as the div on the right keeps overlapping the div on the left

I recently built a React component that consists of two columns. In the left column, there's a calendar while the right column contains some text along with an input and select field. However, I noticed that when I resize the window, the elements on ...

Utilize Dojo to programmatically showcase an image

I'm facing an issue while trying to programmatically display an image using dojo. I have tried using both "dijit/Dialog" and "dojox/image/Lightbox". However, when using the Dialog method, instead of displaying the image, some random characters are sh ...

Is my data secure in Node.js RAM?

I have developed a web application that enables users to create personal pages using Express and Node.JS. Each page is represented as an object, allowing for the creation of new ones with the syntax: new privatePage(name, pswd). As a result, all passwords ...

Is there a way to reverse the hover effect on div elements?

Let's start by examining the code I've written: HTML: <div class="button_container"> <div class="inner_button"> <a href="#" class="button_text">Button</a> </div> <div class="button_side"> ...