Ways to add an array to the dropdown menu and deactivate a single option within it

I have a navigation bar with 5 elements, drop down menu field, textarea and another text field. Here are the requirements:

  1. Initially, all navigation bar elements except Home should be disabled when the document is ready. When the text field loses focus, the disabled attribute should be removed from them and they should be activated again.
  2. All values in the dropdown menu field starting with 001 should be separated and displayed in an additional drop-down menu under "Master" in the navigation bar without the URL part. Values starting with 002 should be appended to an additional drop-down menu under CSS, and values starting with 003 should be added under Javascript, both without the URL part.
  3. If the user clicks on the logout option under the Home window, it should close.

This is a demo: https://jsfiddle.net/ov43ebko/1/

$(document).ready(function(){
 $('.css,.jscript,.jquery').attr('disabled','disabled');
 $('.logOut').click(function(){ 
   window.close();
 });

 // Split lines based on semicolon.
function check(){
var lines = $('.hiddenText textarea').val().split(/\n/);
var texts = [];
for (var i=0; i < lines.length; i++) {
texts.push($.trim(lines[i]));
}
for (var i=0; i < texts.length; i++) {
var removed1 = texts[i].split(';');

$(".masters").append($("<ul><li>").text(removed1[0]));
$(".css").append($("<ul><li>").text(removed1[1]));
$(".jscript").append($("<ul><li>").text(removed1[2]));
}
}

// Split dropdown menu choices into lines.

function c1() {
var resultLines = $('.filledField').find('option').size();
var textArea ="";

for (var i = 1; i <= resultLines; i++) {

var xItem = $('.filledField').find('option:nth-child(' + (i) +  ')').text(); 
textArea +=  xItem ;

//code to split xItem into individual variables
 }
 $('.hiddenText textarea').val('');
 $('.hiddenText textarea').val(textArea);
 check();
 }
 $(".field").blur(function(){
 $('.css,.jscript,.jquery').prop("disabled", false);
 c1();
  });
  });

Answer №1

I trust that this accomplishes what you were aiming for.

1. I need to deactivate all navigation bar elements except Home upon document load. Then, when the text field loses focus, remove the disabled attribute and reactivate them.

To achieve this, I have utilized pointer-events:none to disable li tags as they cannot be disabled using the disabled attribute.

$('.css,.jscript,.jquery').css('pointer-events', 'none');

Subsequently, reenabled by reverting the CSS back to all.

$(".field").blur(function() {
    $('.css,.jscript,.jquery').css('pointer-events', 'all');
    c1();
});

2. I want to sort out values in the dropdown menu field starting with 001 into an additional dropdown menu under the master section in the navigation bar without including the third part in the line (URL). Values beginning with 002 should go under CSS without (URL), and those starting with 003 belong to JavaScript also without (URL).

If my interpretation of your request is correct, I have examined the first parameter value and appended the second parameter value in the appropriate ul under the dropdown menu.

if (parseInt(removed1[0]) == 1) {
    $(".masters ul").append($("<li></li>").text(removed1[1]));
} else if (parseInt(removed1[0]) == 2) {
    $(".css ul").append($("<li></li>").text(removed1[1]));
} else if (parseInt(removed1[0]) == 3) {
    $(".jscript ul").append($("<li></li>").text(removed1[1]));
}

You can view a demo of this on this fiddle.

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

Utilizing CSS to set a map as the background or projecting an equirectangular map in the backdrop

How can I set an equirectangular projection like the one in this example http://bl.ocks.org/mbostock/3757119 as a background for only the chart above the X-axis? Alternatively, is it possible to use an image of a map as a CSS background instead? .grid . ...

What is the best way to distinguish between enabled buttons using Protractor?

I am facing a challenge with a table containing 20 buttons. Half of these buttons are disabled while the other half is enabled. I am looking for a way to filter out the enabled buttons and click on each of them using a for loop. The buttons that I want to ...

Animate images using mouse vertical movement

Creating websites is just a hobby for me, not something professional. Recently, I came across a beautifully designed website that had some unique features I hadn't seen before, like placing three images in one div (which I researched and learned how t ...

Using xsl:attribute with conditional statements and handlebars for dynamic content

I attempted to use handlebars to set xsl:attribute. Here is the code snippet: <input type="text"> {{#if_eq line_type 0}} <xsl:attribute name="disabled">true</xsl:attribute> {{/if_eq}} </input> Unfortunately, this approach ...

Disable a button during an AJAX request

Whenever a button is clicked, the record is saved to the database without refreshing the page using AJAX. I have implemented the AJAX code successfully. Now I need guidance on how to manage the state of the Submit button - enabling/disabling it dynamicall ...

ChessboardJs: JavaScript Boards Function Properly on Initial Use Only

Update: The page code can be accessed via my page URL. I'm unsure where the issue lies. Your assistance is appreciated. Issue: Initially, when clicking on the chess puzzles page, everything works fine. However, upon re-clicking from the homepage, th ...

Nodejs and javascript are utilized to create dynamic SES emails

I have successfully implemented sending an email using node-ses client.sendEmail({ to: to_id, , cc: cc_id, , bcc: bcc_id, , subject: 'greetings' , message: 'your <b>message</b> goes here' , altText: 'plain text& ...

Attempting to design a modal template using Angular UI framework

I am attempting to create a reusable template for a Modal Window. Link to my code Unfortunately, I am encountering an error when trying to implement the Modal. The error message I am receiving is found at this link. It seems to be related to an issue wit ...

Ways to align a group of rows in the center of a document

I'm struggling to center these rows in the middle of the page. Using a Bootstrap template, I've been customizing it to suit my webpage. https://i.sstatic.net/E9hHq.png I want the rows to be centered just like the text above them. Originally a che ...

What is the best way to hide an entire div when content is deleted?

Within a div, I am incorporating this specific class: .successful { width: 100%; background-color: #c2f5b2; border: solid 1px #89bc79; color: #29ac00; padding: .5% 1%; margin: 1% 0; display: bloc ...

Navigating through Three.js using trackball-inspired controls

I've been immersed in developing a 3D game for a while now, and I've hit a roadblock when it comes to the controls. I've implemented custom pointerlock controls, but I'm struggling to get the rotation to mimic the behavior of three.js T ...

The unique filter in Angular.js seems to be malfunctioning

I ran into an issue with my code where I expected my paragraphs to filter out values based on unique age, but instead I encountered the unknown provider error. How can I resolve this? <html> <head> <script src="https://cdnjs.cloudflare.com/ ...

What is the best way to incorporate multiple images along with additional input fields in Vue.js HTML?

My HTML code needs to include a "sez" array format and the ability to add multiple images by providing an "add image" button that allows clients to add images as needed. <form method="POST" enctype="multipart/form-data" v-on:submit.prevent="handleSubmi ...

How can I transfer a MySQL record ID between pages?

I have a search form that, when you click on the "more info" link for a record, it opens a new window to display additional information. I use <a href=more_info.php?id=$rows[id]> to pass the id to the next page and it works great. In that next page, ...

Can the input type "color" be set as read-only?

<input type="range" name="slider"> Unfortunately, this solution isn't functioning as expected. Do you have any alternative recommendations? ...

Retrieve the last six elements from the array in JavaScript after the original array has undergone filtering

I'm currently working with an array that filters out today's games and retrieves the first 6 items. However, I now want to retrieve the last 6 items from the filtered array. Here is what I have tried: fixtures.filter(fixture => { return f ...

Obtain the outline shape in ThreeJS (duplicate border)

When working with a geometry, I often need to view it from different angles. For example, if I position my camera from the top, I want to be able to extract the outline of the geometry as a new shape. This allows me to then Extrude this shape further. In R ...

I am encountering a 302 error when attempting to sideload images on Imgur using the API

I've been experimenting with sideloading using imgur's API. $.get("http://api.imgur.com/2/upload.json?", { url: www.example.com/blah.jpg },function(response){ var url = response.upload.links.original; var thumb_url = response ...

Guide on integrating AJAX partials on tabs using AngularJS

Is it possible to include nested partials with forms inside the partial tabs, like this: <ng-include src="'form_group.html'"></ng-include> Furthermore, there seems to be an issue with the binding of expressions {{}} to the actual ou ...

Can we condense the code to create a more concise and efficient function?

Can someone help me refactor this code snippet below into a function and combine the two IF statements? Many thanks! let value = productDetails.recentPurchaseDate; if (!productDetails.salesPrice && !productDetails.recentPurchaseDate) { value = false; } ...