3

I have a navigation bar with 5 elements, drop down menu field, textarea and another text field. what i need:

  1. to disable all navigation bar elements except Home when document be ready. then when i blur the text field remove attr disabled from them and activate again.
  2. to separate all the values in the dropdown menu field started with 001 in additional drop down menu under the master in the navigation bar without the third part in the line (url) , append values started with 002 in additional drop down menu under CSS without (url) and 003 under javascript also without (url) .
  3. when user click in logout option under home window close.

this is Demo:https://jsfiddle.net/ov43ebko/1/

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

     // to 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]));
    }
    }

    // to split dropdown menu choices to 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();
      });
      });
M.Gooda
  • 127
  • 1
  • 11
  • #3 can't be done. JS can't close a window that isn't opened by it. You may get some tricks but FF and chrome won't support them. Please refer this - http://stackoverflow.com/a/19768082/4719761 – Developer107 May 10 '16 at 05:59

1 Answers1

0

I hope that this is what you wanted to achieve.

1. to disable all navigation bar elements except Home when document be ready. then when i blur the text field remove attr disabled from them and activate again.

For this, have given pointer-events:none to disable li tags as they can't be disabled using attribute disabled.

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

And then enabled it by setting css back to all.

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

2. to separate all the values in the dropdown menu field started with 001 in additional drop down menu under the master in the navigation bar without the third part in the line (url) , append values started with 002 in additional drop down menu under CSS without (url) and 003 under javascript also without (url) .

I may have misunderstood this point but here is what I think you wanted. Have checked first parameter value and accordingly appended the second parameter value in ul under drop down 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]));
}

Please refer this fiddle.

Developer107
  • 1,728
  • 2
  • 14
  • 24
  • step two isn't quite right still. It seems as though each time the input field is clicked the tags load onto the menu lists. Should probably add a step at the beginning to drop prior `
  • ` elements before loading new ones - a bit clunky, but will likely do the job. likely a '$(".masters ul, .css ul, .jscript ul").empty();` will do it on line 14 or so
  • – Alex Durbin May 10 '16 at 07:20
  • 1
    Have updated the fiddle where previous `ul` gets removed on clicking input again. – Developer107 May 10 '16 at 07:22
  • I am glad to help :) – Developer107 May 10 '16 at 11:23