[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

JavaScript

121K

Solutions

42K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.

Share tech news, updates, or what's on your mind.

Sign up to Post

I need to get information from a XML file where this file is auto upload every 30 seconds.
I want to show this information in a website.

Just to show an example, my website is a radio, and I want to show to users what music he listen.
0
Why Diversity in Tech Matters
LVL 12
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference ithrough the Colors of STEM program.

I have this code in program 1:
<!DOCTYPE html>

<html>
<head>
<title>Print Single Form</title>
<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">

    <title>Backflow Assembly & Test Report Form</title>
    <style>
        .nopadding {
            padding: 0 !important;
            margin: 0 !important;
        }
        
        .wrapper {
            max-width: 767px;
            min-width: 480px;
            margin: 0 auto;
        }
    </style>
	<script>
	user = <? print $_SESSION['user']; ?>;
	fname = "<? print $fname; ?>";
	ac = "";
	fr = "<? print $fr; ?>";
	ems = "<? print $_GET['ems']; ?>";
	loc = "<? print $loc; ?>";
	function open_pdf_win() {
		str = loc + fname;	
		window.open(str);
	}
	function ask_email() {
		jj = confirm("Email printed form to my email?");
		if (jj) {
			

Open in new window

0
I am trying to display a custom message when a user closes or about to close a browser tab. In the earlier versions of the browsers I could do this using onunload or onbeforeunload events and display a pop-up message but the newer versions do not allow me to customize the message. Is there anyway I can display a customized message when the user closes the browser tab or when clicks on the close button of the browser tab? A tool-tip could also work when the user is hovering on the close button or clicks on the close button of the browser. Thank you for any help.
0
How can I read the client's machine/computer name from the browser? Is it possible using JavaScript?
0
Experts!

I have created a Node.JS web app with two APis. One of the APIs is GUI where the end-user sees the GUI. The second API is the auth guard that will go and talk to 1L using OPENID > authenticate > fetch user profile and render information to the GUI for the end-user.

We originally wanted to use SAML assertion (SSO) similar to Zendesk or Others that when someone is authenticated to 1L and you navigate to the site domain.zendesk.com the established logged in token just redirects you to the site. When you are not logged in to 1L and you go to the site you are redirected to 1L for auth then redirected back to the site of choice once you successfully auth.

Our application does not have a user database, instead, we are banking on 1L to do authentication for us and also pass through user information to our second API so that we can then pass specific end-user details from the internal side to the GUI. The end goal is to be able to authenticate with 1L and be redirected to the sales.cbac.com and be able to know user specific details about the current user, but that user is to never have to access the login page

Right now, we had to spin up a login page that will accept user info > sends info to auth guard to call 1L auth > returns valid user and user profile info > all using OPENID.

What is the best approach? It seems like we are missing something.

API URL1 (GUI) - sales.cbac.com API URL2 (auth guards - OPENID) - sales-api.cbac.com Current state you land at …
0
Hello Experts

I have been able to previously install npm install express into individual folders earlier today but now can't.

If I attempt to install npm express into a targeted folder, it loads in the cmd line but does not generate the package and node_modules file and folder that it's suppose to in the targetted folder.

Is there a solution available for this? (no static file servers/request, only vanilla npm install express). I need to install the express module into any folder that is targetted/destination on a desktop.
0
I have few icons and images in svg format, that I need to untilize in asp.net site.
I added all the svg icons in an image tag as such

<img src=".../icon.svg>

this way I can't set the color of the svg icon. as there are quite a few icons , i'm using , what would be a best approach  to use such svg icons , so that i can set the color as well.
0
Hello Experts,

I am looking for a solution to a ER_NOT_SUPPORTED_AUTH_MODE that is stating that the authentication protocol is not supported requested by the server, consider upgrading.

The latest version of MYSQL out is 8.0.12 and has no updates to install. MySQL and Node.JS are being used in combination for this demonstration. The node.js file runs fine in the win cmd line when referencing the file.

There is a password that I have set to the MySQL server, which will be needed. This is a LocalHost. Running the page set at the port 3000 returns as a "unable to connect error"

I have tried this solution to no avail in the mySQL command line in an attempt to bridge the issue:

use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';

Only the mySQL command line can be used (excluding workbench, etc). This seems to be a CLIENT_AUTH problem with the latest mySQL version?
index.js
0
I have a Nutanix / Dell 3 node environment, I have managed to change the host Ip addresses to a new subnet and I have also change the CVM ip addresses, but I am having problems finding a way to either change the Cluster IP address from the CLI or break the cluster and rebuild with new IP and name.   Can anyone help?  I am not that conversant with Linux so a simple explanation if possible to get this done.

Many thanks

E.
0
Has been almost a year that I switch to Auth0 in order to manage my customer's access to the dashboard of my application. Nowadays I need to implement access for a RESTFULL API.

If I follow the instructions in order to secure the NodeJS app using JWT it works like a charm. The issue is that I am not properly sure on the implementation for the end user in order to get the token needed for access this API.

I thought of creating the tokens on the dashboard or just use a server side implementation for the login/authentication. I did the last using the access to my own database before and worker amazingly. My issue is that I am not completely sure on how to do it for the end user using Auth0.

Would be great if you can guide me in order to implement the login/authentication side of the API using auth0 and nodejs.
0
Big Business Goals? Which KPIs Will Help You
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

How do I have a table appear directly ontop of another table in browser after the user has clicked the submit button so only the resulting table is shown? I need to move the existing table from below only to appear after the submit button where the first table is situated.

EDIT: Am looking for solution where the resulting table appears after submit button. It cannot appear as a dialog/pop-up but only directly on the page. The resulting table is located in the same place where the first table is. Only resulting table must show.  

index.html
app.js
0
How to order below json by Location , Name ="Total" comes before detail

{
   "records":[
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Qty":16,
         "Name":"Total"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Qty":11,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Qty":5,
         "Name":"Total"
      },
        {
         "Location":"US",
         "RecordType":"Grocery",
         "Qty":17,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Productid":123,
         "Qty":5,
         "Name":"Apple"
      },
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Productid":124,
         "Qty":11,
         "Name":"Bananna"
      },

      {
         "Location":"US",
         "RecordType":"Grocery",
         "Productid":223,
         "Qty":6,
         "Name":"Rice"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Productid":224,
         "Qty":11,
         "Name":"Beans"
      }
   ]
}

Open in new window




How to rearrange json so Location + Total comes before detail

{
   "records":[
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Qty":16,
         "Name":"Total"
      },
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Productid":124,
         "Qty":11,
         "Name":"Bananna"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Qty":11,
         "Name":"Total"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Productid":224,
         "Qty":11,
         "Name":"Beans"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Qty":5,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Productid":123,
         "Qty":5,
         "Name":"Apple"
      },
        {
         "Location":"US",
         "RecordType":"Grocery",
         "Qty":17,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Grocery",
         "Productid":223,
         "Qty":6,
         "Name":"Rice"
      }
   ]
}

Open in new window

0
How to build table using javascript for below JSON , I want to display Total for each location and RecordType first and then detail for location and recordtype and add extra blank row for each different category


{
   "action":"query",
   "Warehouse":"NJ",
   "records":[
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Qty":16,
         "Name":"Total"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Qty":11,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Qty":5,
         "Name":"Total"
      },
        {
         "Location":"US",
         "RecordType":"Grocery",
         "Qty":17,
         "Name":"Total"
      },
      {
         "Location":"US",
         "RecordType":"Fruits",
         "Productid":123,
         "Qty":5,
         "Name":"Apple"
      },
      {
         "Location":"UK",
         "RecordType":"Fruits",
         "Productid":124,
         "Qty":11,
         "Name":"Bananna"
      },

      {
         "Location":"US",
         "RecordType":"Grocery",
         "Productid":223,
         "Qty":6,
         "Name":"Rice"
      },
      {
         "Location":"UK",
         "RecordType":"Grocery",
         "Productid":224,
         "Qty":11,
         "Name":"Beans"
      }
   ]
}

table
Location  Name   RecordType    ProductID, Qty
US        ,Total   ,Grocery    ,          ,6
US       …
0
I am new to knockoutjs. I am creating a table with racers. I can show racer events, but i want to change the position of the racer in the table manually by click button. They perform swap function, but they do not bind values in the table. Without using click action data bind in table with swapping value.
my sample coding is here,
var PlanetsModel = function() {
    self.Racer = ko.observableArray([
        { id: "Racer-101", rank: "5"},
        { id: "Racer-102", rank: "2"},
        { id: "Racer-103", rank: "1"},
        { id: "Racer-104", rank: "4"},
        { id: "Racer-105", rank: "7"},
        { id: "Racer-106", rank: "8"},
        { id: "Racer-107", rank: "9"},
        { id: "Racer-108", rank: "3"},
        { id: "Racer-109", rank: "6"}
    ]);
 
    this.typeToShow = ko.observable("all");
    this.displayAdvancedOptions = ko.observable(false);
	//console.log(self.Racer()[5].rank);    //find particular racer rank value
    
	//setTimeout(function () {
		this.addPlanet = function(type) {
			self.Racer.push({
				id: "New planet",
				rank: type
			});
		};
		console.log(this.addPlanet);
	//}, 4000);
    this.showRacer = ko.computed(function() {
       return self.Racer();        
	}, this);
	var newData = self.Racer();
	console.log("First array : " + JSON.stringify(newData));
	
	/* swap array values based on temp variable */
	self.moveup = function() {
		function swap(input, index_A, index_B) {
			var temp = input[index_A];
			 
			input[index_A] = 

Open in new window

0
Hi Experts,
Need some urgent help on quering json object please


1. How to query attached json file and return true or false based on string contains logic check.
2. Parse each stdout element in the json file.
3. Loop through each stdout and check for if it contains "HELLOWORLD_APPLICATION_DEPLOYMENT_SUCCESSFUL"

below filter will return all stdout element. but not able to figure out how to include contains logic and get true/false
jpath = plays[*].tasks[*].hosts.localhost.stdout


Have attacehd few screenshot on how i'm trying this online json editor

https://jsoneditoronline.org/
json_editor1.jpg
json_editor2_with_filter.jpg
success.json
0
I created a modal dropdown form with four dropdown lists, with the fourth dropdown containing a link to a document to display once user clicks the submit button. All four dropdowns work fine, however when clicking the submit button the document does not display. The form simply continues to display, log indicates 'Cannot read property '0' of undefined'.. Any help is appreciated.

var selectedOptions = {};

        $('#link1').on('change', function () {
            var a = $(this).val();
            selectedOptions['1'] = a;
            selectedOptions['2'] = a;
            selectedOptions['3'] = a;
            if (a !== '') {
                for (var i = 0; i < dataSecondSelect[a].length; i++) {
                    $('#link2').append($("<option></option>")
                            .attr("value", dataSecondSelect[a][i])
                            .text(dataSecondSelect[a][i]));
                }
            }
        });

        $('#link2').on('change', function () {
            var a = $(this).val();
            selectedOptions['1'] = a;
            selectedOptions['2'] = a;
            selectedOptions['3'] = a;
            if (a !== '') {
                for (var i = 0; i < dataThirdSelect[a].length; i++) {
                    $('#link3').append($("<option></option>")
                            .attr("value", dataThirdSelect[a][i])
                            .text(dataThirdSelect[a][i]));
                }
            }
        });
        

Open in new window

0
I've created an accordion with anchor links, my issue is how can I trigger the javascript to open the active accordion panel when the anchor link is selected.

<script>

    $(function() {
    $('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//,'') == 
    this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) 
    +']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
    });
    });
</script>

Open in new window


    <div class="Test">
        <a href="#Link 1st">A</a>
    </div>

   <button class="accordion"><strong><a id="Link 1st"></a>Link 1st</strong> 
   </button>

   <div class="panel"><br />
     <H4>Link 1</H4>
   </div>

Open in new window

0
Hey all I am using RFT in order to automate a page on a Pega website page. However, the automation doesn't seem to be able to fire off the change event of the input that I am inserting a string of text into. This input box seems to be located inside an iframe and perhaps this is the reason why its not firing the onchange event when losing focus on that input box?

RFT does use Selenium in their program to interact with the web page.

The html of the input box:

<input 
    data-id="204083727717650" 
    data-ctl="["TextInput"]" 
    id="BBOX" 
    maxlength="15" 
    validationtype="required" 
    value="" 
    name="$PpyWorkPage$pBBOX$pBBOX" 
    class="leftJustifyStyle" 
    data-change="[["refresh", 
                   ["otherSection",
                    "RecordInformation", 
                    "", 
                    "&amp;=", 
                    "", 
                    "BBOXOnChange,",
                    ":event",
                    "",
                    "pyWorkPage.BBOX"
                   ]
                 ]]" 
    type="text">

Open in new window


The Selenium code I have tried is this:

driver.switchTo().frame(driver.findElement(By.name("PegaGadget")));     

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("BBOX")));
final WebElement BBOXInputBox = driver.findElement(By.id("BBOX"));

BBOXInputBox.click();
BBOXInputBox.click();
Thread.sleep(2000);
BBOXInputBox.sendKeys("204083727717650");
Thread.sleep(2000);
BBOXInputBox.sendKeys(Keys.TAB);
Thread.sleep(2000);
BBOXInputBox.sendKeys(Keys.BACK_SPACE);
Thread.sleep(2000);
BBOXInputBox.sendKeys("1");
Thread.sleep(200);
BBOXInputBox.sendKeys(Keys.TAB);
Thread.sleep(2000);

Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.id("FirstName_U")), 5, 5).click().build().perform();

driver.findElement(By.id("FirstName_U")).sendKeys("something");

Open in new window


And I am trying my best to find this function above in their 30 or so of .js files for any one page.

So someone more knowledgeable than I in the area of this type of coding in JS please set up and let me know what I should be looking for in the .js source code so that I can fire this change event manually within code.

It seems when I click on the text box, input a few letters and then either tab or click on another input box on that same form it fires some type of event/function that populates a label on the page.

What I have been looking for within the .js source code would be a function called refresh(...) or something along the lines of refresh: function(...)... or _refresh: function(...)... but I haven't been able to find anything that resembles the parameters its sending to that function.
0
I have a page with a number of images on. When these images are clicked this brings up a pop out (using bootstrap modal) that has a form on it. What I would like to happen is that when a certain image is clicked it selects a radio button on the form and also opens the modal box.

The link that selects a certain radio button might be on the page more than once so I cannot use ID.

Here is how I have the html

	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option1"><img src="image1.jpg"> <h5>Name 1</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option2"><img src="image2.jpg"> <h5>Name 2</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option3"><img src="image3.jpg"> <h5>Name 3</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option4"><img src="image4.jpg"> <h5>Name 4</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option5"><img src="image5.jpg"> <h5>Name 5</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option6"><img src="image6.jpg"> <h5>Name 6</h5></a>
		
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option1"><img src="image1.jpg"> <h5>Name 1</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option2"><img src="image2.jpg"> <h5>Name 2</h5></a>
	<a data-toggle="modal" data-target=".bs-example-modal-lg" class="option3"><img src="image3.jpg"> <h5>Name 3</h5></a>
	
	<div 

Open in new window

0
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

After processing data, I am trying to send results back to one of three pages, depending on what is being processed and the results. I thought it would be a simple matter to send the data to be picked up by a JavaScript file to display in an alert window. My Web console is giving me the following error:
SyntaxError: "" string literal contains an unescaped line break
There are no line breaks in the content. It is just one small string of text.
However, alternatively, if there are errors, I need to send an array to display those errors.
When I try to encode that array, I get the following error:
SyntaxError: expected expression, got '%'
The encoded string looks like this: "%5B%22Source%3A+%22%5D"

Perhaps there is just a more intelligent way to do this. I could just create my own window in PHP and forget about the alert, but I already use this alert process for include files so it would be nice if I could use the same result processing.

Here is what I am doing with the results of the remote file:
(First, the function for the code below)
<script type="text/javascript">
   function AddParameter(form, name, value)
   {
      var $input = $("<input />").attr("type", "hidden").attr("name", name).attr("value", value);
      form.append($input);
   }
</script>

Open in new window

$Act (for "action") is the file the data will return to.  $AppID is just a record number.
This is really one less redundant code set, but easier to show this way. It either sends a result message or errors.

Open in new window

0
When I click the date time picker, it currently defaults to the current date and time, I need it to default to the date/time set in the input field.

So if I have a datetime as 2018-12-25 09:00 (a future date) in the field and I click it, the picker display's today's date, I need it to display the picker based on 2018-12-25 09:00.

The date that is displayed is being pulled from a database and the page shows a large number of datetime picker fields, so I cannot just code in the 2018-12-25 09:00 time to the settings.

I am using this datetime picker: https://xdsoft.net/jqplugins/datetimepicker 

My code is:

<script src="js/datetimepicker/datetimepicker.js"></script>
<script>
$('.datetimepicker').datetimepicker({
dayOfWeekStart : 1,
    lang:'en',
    format:'d/m/Y H:i',
    allowTimes:['08:00',     '08:30',     '09:00',   '09:30',     '10:00',        '10:30',     '11:00',       '11:30',       '12:00',       '12:30',    '13:00',   '13:30',       '14:00',         '14:30',      '15:00',     '15:30',      '16:00',        '16:30',       '17:00',   '17:30',    '18:00',    '18:30',     '19:00',      '19:30',     '20:00',      '20:30',       '21:00',     ],
});
</script>

Open in new window


My html/php is

echo "<form action='#' method='get'>
<input type='text' name='val' class='datetimepicker' value='".$row['eventdate']->format('D d/m/y g:i a')."'  autocomplete='off' style='float:left; width:150px'/>
<input type='hidden' name='eventid' value='".$row['eventid']."'/>
<input type='hidden' name='id' value='".$row['id']."'/>
<input type='hidden' name='field' value='eventdate'/>
<input type='hidden' name='action' value='updatefield'/>
<input type='submit' value='&#10004;'  style='float:right'/>
</form>

Open in new window


Any advice would be gratefully received.
0
I load a php generated html page in the browser & it just get's stuck. Nothing shows on the page (in the browser). I have tried it with FireFox & Chrome.

Some clues:
 This code is at the VERY end of the document (obtained by "view source" in Firefox).
<script>
ddocs="";
nosumm = "1"
	if (nosumm == "1") {
		window.location = "send_email_ls250.php?ddocs=" + ddocs;
	} else {
		document.getElementById("container").style.visibility = 'visible';
	}	
</script>
</body>
</html>

Open in new window


I'm expecting it to drop through and execute this javascript, seems like it doesn't.

Can that be happening? It's ignoring the last <script>.

As a reference, I attached the COMPLETE HTML file.
summaryf.html
0
Hello Experts,

I am trying to change background color of the Field Color Based on Value enter by user . Please check attached file for more details.
color1.php
ChangeColor-copy.jpg
0
I am using ISOTOPE filtering script for PHP avaialble at:
https://isotope.metafizzy.co/

Open in new window


This works fine in a single php file.  But when I embed that code in a modal window, the isotope not works.
Any suggestions will greatly help me.

Thanks
0
The following javascript on a simple webpage used to work.  It would display a thumbnail gallery at the bottom and when you click on a thumbnail, the corresponding video would play.  Now the mouse doesn't even change anymore when you hover over the thumbnails and clicking on them doesn't do anything.  I'm not really a javascript coder, I just lifted this code from somewhere else years ago and it worked back then.  Let me know if you need any other info.  

 
    <script src="javascript/jquery.1.4.js" type="text/javascript"></script>	
    <script src="javascript/scripts.js" type="text/javascript"></script>	
    <script src="http://cdn.jquerytools.org/1.2.0/jquery.tools.min.js"></script>

     <script>
            $(function() {
                var nowPlay="The Ops Family - Part 1";
                $("p").text(nowPlay);
                $(".scrollable").scrollable();            
                $(".items img").hover(function() {
                  $("p").text($(this).attr("title"));
                }, function() {
                  $("p").text(nowPlay);
                });
                $(".items img").click(function() {
                	// see if same thumb is being clicked
                	if ($(this).hasClass("active")) { return; }
                	nowPlay=$(this).attr("title")
                	var url = "video-files/"+nowPlay+".flv";
                	
                	LoadPlay(url,'flv')
                	
                	$(".items img").removeClass("active");
     

Open in new window

0

JavaScript

121K

Solutions

42K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.