JavaScript

119K

Solutions

71

Articles & Videos

41K

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 have the following piece of code that is needed to build and add rows under the right headings in an html table.
var mileStoneHtml="";
		var typeArray = [];
		var headingName = "";
		for(var i =0; i < data.d.results.length; i++) 
		{	
			headingName = data.d.results[i].Milestone_x0020_Type;
			
			if (typeArray.indexOf(headingName) === -1){
				typeArray.push(headingName);
				
				
				tableRow = document.createElement("tr");
				tableRow.id=headingName;
				tableRow.style.backgroundColor = "#EEEEEE";
				tableCol = document.createElement("td");
				tableCol.colSpan = 5;
				tableCol.textContent = headingName;
				tableRow.appendChild(tableCol);				
				console.log(tableRow);
				tbl = document.getElementById("tblMilestone");
				console.log(tbl);
				console.dir(tbl);
				tbl.appendChild(tableRow);
			}
					mileStoneHtml = "<tr>"+
					"<td>"+data.d.results[i].MilestoneDescription+"</td>"+
					"<td>"+data.d.results[i].Planned_x0020_Date+"</td>"+
					"<td>"+data.d.results[i].Revised_x0020_Date+"</td>"+
					"<td>"+data.d.results[i].Actual_x0020_Date+"</td>"+
					"<td>"+data.d.results[i].Milestone_x0020_Type+"</td>"+
				"</tr>";		
				
				var newRow = $("#"+headingName).append(mileStoneHtml);
				console.log(newRow);
//				document.querySelector("#tblMilestone").appendChild(mileStoneHtml);					
		}													

Open in new window


It needs to look like this
correct rendering
but it looks like this
incorrect rendering
0
Get 15 Days FREE Full-Featured Trial
LVL 1
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Hi Experts

Could you point how to obtain the values from the Javascript  Objects?

Javascript
console.log(Object.values(where));

Open in new window


Produced
img001
So, what's needed to obtain these Object's values?

Thanks in advance!
0
Dear Experts,
I am creating an online database portal that requires a user login.  Once logged in, the user has access to various pages, one of them will jump to a payment center of a bank.  (In my case, Union Bank, https://www.hoabankservices.com/Services.aspx)

Is there anyway that I can inject the userID from before jumping to this payment center, and have it automatically show up in User ID box?
Please advise.  Thank you.
0
I need to write a rule in my apache htaccess file to redirect:

/insurance-plans/year/schools/international-student-plans-2015?s=136&l=5000
to:
http://%{SERVER_NAME}/insurance-plans/year/schools/international-student-plans-2017?s=136&l=7000

The rule I wrote is as follows, but it does nothing:

RewriteRule ^insurance-plans\/year\/schools\/international-student-plans-2015?s=136&l=5000$		http://%{SERVER_NAME}/insurance-plans/year/schools/international-student-plans-2017?s=136&l=7000	[R=301,L,NC,NE]

Open in new window


I'd be grateful if someone would show me the correct htaccess code to implement my redirect.

Thanks,
Jon
0
I have a multiple choice quiz that is either correct or incorrect. Right now the code works so that correct or incorrect is shown, but I need to add logic that shows that the choice was correct because that was the right answer or if it was correct to not select it, or the choice was incorrect because that was the correct answer to choose.
Below is the code I am currently using and the HTML that has the question.
Any help or pointing in the right direction is appreciated.

Javascript
// JavaScript Document
//Function to show all explanations and tell if the user was correct. 
function show_all()
{  
  var 	
 answers = document.getElementsByClassName("explanation"),
		checkboxes = document.getElementsByName('field'),
		corrects = document.getElementsByClassName("correct"),
		incorrects = document.getElementsByClassName("incorrect");
		
		
  for(var i = 0; i < answers.length; i++)
  {
        
answers[i].style.display = 'block';
	
	// check the checkbox selection
	if (checkboxes[i].checked) {
		//If the answer and choice is incorrect
		if (checkboxes[i].getAttribute('value') === 'incorrect') {
			incorrects[i].style.display = 'block';
			
		}
		else {
			corrects[i].style.display = 'block';
		}
	}
	else {
		if (checkboxes[i].getAttribute('value') === 'correct') {
			corrects[i].style.display = 'block';
		}
		else {
			incorrects[i].style.display = 'block';
		}
	}
  }
 

} 

Open in new window


HTML
<form id="submitform">
    <div id="main" class="container-fluid">
 

Open in new window

0
Hi

See my code: https://codepen.io/petewinter/pen/weqWeq

Can you please help with the following...

1) My list should be sorting alphabetically. I assume this is not happening correctly due to the tags within the <li>, but I'm not sure how to edit the code?
2) When a checkbox is checked I would like selected checkboxes to go to the top of the list alphabetically, then when unchecked go back back down and sort alphabetically again.

Help would be much appreciated.
0
I'm looking for a way to asynchronously load the contents of a whole div. I'd like to delay the loading of everything in the div. Right now, everything is loaded all at once and it's not bandwidth efficient.

https://codepen.io/anon/pen/GENGJW
0
Hi,

I am looking at a few different things. I am using ASP.NET 4.0 and VB.NET code-behind.

The main situation is this.

I have a page with an iFrame.  We'll call that Page 1 and the page in the iFrame as Page 2. The page of the iFrame on Page 2 is a URL location is external and that page cannot change.

Page 1 is polling the database running on reload of the page which invokes the Page_Load on the reload. That Page_Load is executing the stored procedure to check certain values in a table. Page 2 (the one in the iFrame) is where certain information is entered and will have a submit button. After a period of time, information from the Page 2 will go into the same table that I am polling on Page 1.

What is going on is every time Page1 reloads (based on like 10 second interval) the data in Page 2 (in the IFrame) is lost.

How can I keep that from happening?

I can think of one way, off the cuff, and that is to use the Page 1 and Page 2 as a frameset. And one Frame (for the Page 1) is doing the polling and reloading... The other frame is doing the Page 2 but in an iFrame.

When the user hits the "Submit" button on the second frameset (Page 2) then break out of the frameset and only have the Page 1.

Break out of the Frameset from the code behind of Page2 with JavaScript like? Or is there another way?

Page.RegisterClientScriptBlock("ResetPage", "<SCRIPT>top.location.href=" + Page1URL + "</SCRIPT>");

Open in new window


That is one option. Is there another …
0
HI experts, codes below are able to calculate profit percentage. However, when it comes of writing comma "," in a number it will no longer calculate. For example, if i write 1,000.00 as the capital price (CP) and 1,200.00 as the selling price (SP), the solution will not work. However, if I write 1000.00 as the  (CP) and 1200.00 as the  (SP) the solution will answer. Any help please! Thank you.

<!DOCTYPE html>
<html>

<body>
<p>Capital Price</p>
<input type="text" id="A9" onkeypress="CalculateProfit()" onkeyup="CalculateProfit()"/>
<br/>
<p>selling Price</p>
<input type="text" id="A8" onkeypress="CalculateProfit()" onkeyup="CalculateProfit()"/>
<br/>
<p>result</p>
<input type="text" id="A10"/>

<script>
function CalculateProfit()
{
	var 	sp = parseFloat(document.getElementById("A8").value);
			sp=sp.toFixed(2);
			sp=sp.replace(/\,/g,'');
			
	var 	uc = parseFloat(document.getElementById("A9").value);
			uc=uc.toFixed(2);
			uc =uc.replace(/\,/g,'');
			
	var 	prt = (sp /(.01 * uc) - 100);
	var 	n = prt.toFixed(2);
	
	document.getElementById("A10").value = n + "%";  
}

</script>
</body>
</html>

Open in new window

0
If i have the following, are there any issues using a relative path for s.src?  I've tested and it works fine but didn't know if there were any gotchas with this?
var scripts = document.getElementsByTagName('script')[0]; 
	    var s = document.createElement('script'); 
	    s.async = true; 
        s.src = "/scripts/bk.js"; 
	    scripts.parentNode.insertBefore(s, scripts); 

Open in new window


Thanks!
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Hello
I am using a script that backups and restores mysql databases. The script works fine until I include an external JS file, which is when I get the title error in firebug. There is a lot of code but I think I can narrow the error to line 692 but what ever I try, I keep getting the error.

I must add I never created the script so cannot give any further info on it's content, but it does what I want it to do, apart from this error.

I would be grateful if somone could help with this. Many thanks

<?php

// Report errors

error_reporting(E_ERROR | E_PARSE | E_NOTICE);

// error_reporting(E_ALL);	//Debug purpose

$host = 'localhost'; //HOST;//eg:localhost
$username = 'root'; //USER;//self explanatory
$passwd = ''; //PASSWORD;//self explanatory
$charset = 'utf8'; //charset keeps preferred character encoding
$port = '3306'; //self explanatory
$dateformat = 'd-m-Y H-i-s-A'; // will be appended to database backup file name eg:test_2016-Oct-25-10-30-54-AM.zip

// small utility function to detect whether secured server or not

function isSiteSSL()
{
  return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443;
}

$url = (isSiteSSL() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

if (isset($_SERVER['QUERY_STRING'])) {
  $url = str_replace('?' . $_SERVER['QUERY_STRING'], '', $url); //removing query string to get exact url
}

$url2 = $url; //$url2 used for building download url
$url.= 

Open in new window

0
Good Evening,

I have a form that needs to be 508 compliant --  Accessibility.  The form has 1 dropdown and one file input after the dropdown has a value selected and using the tab key how would I set the focus o the input part of the fileupload file type so as not to fail 508.  Tabbing now the focus skips over the input and snags the browse button but if the user then hits enter it triggers validation rather than the window asking for the file to choose.

Someone please help I am very new to 508 and work for the government so this will have to be 508 compliant to get to production.  I have tried focusout onchange and a couple of others but I know I am not doing it accurately.
0
1. I followed examples in the link below and coded a map. It works. You can see a map here:

 http://leafletjs.com/examples/choropleth/

You see if you zoom out, you'll see Hawaii and Alaska.

2. I've been asked to make it look like this...Have Alaska and Hawaii next to the US
https://www.highcharts.com/maps/demo/us-counties

3. The Leaflet link in step 1 has the "us counties.js" file

4. I looked at Highchart's JS file (you can see the link in JSFiddle that comes with Highcharts, step 2 above).
    Looks like they have Alaska and Hawaii bundled in a separate section of the JS file and then they have the rest of the states.

Anyone has worked with Leaflet.Js and got Hawaii and Alaska moved next to the US?
0
I am using Modernizr to detect if autoplay is available in the browser. Then, I am displaying either a video or a Javascript-based slide show depending on the result. Here is my code:

videoAutoPlayCheck=setInterval(videoCheckAutoPlay, 1000);
videoCheckAutoPlay();

function videoCheckAutoPlay(){
	Modernizr.on('videoautoplay', function(result){
		if (Modernizr.videoautoplay){
			//PLAY VIDEO
			window.clearInterval(videoAutoPlayCheck);
		} else {
			//PLAY SLIDE SHOW
			window.clearInterval(videoAutoPlayCheck);
		}
	});
}

Open in new window


I am getting unpredictable results in Chrome, however this seems to be working in all other browsers. Researching the issue on Google, there are posts from a couple years ago describing what I am seeing. However, I would have thought that enough time has passed that Modernizr would have fixed that issue.

To describe what is happening, sometimes Chrome loads the video, sometimes the slide show. There doesn't seem to be any way to predict... in fact, sometimes reloading the page brings the opposite result as the previous page load.

Is there anything wrong with my code, or is this still a known issue with Modernizr? Or should I be looking for some other solution?

Thank you.
0
plz help
0
Hi,
I have tried to put together a simple responsive slider on the home page here http://www.peterlane.co.uk.gridhosted.co.uk/

Here is the code in my header...
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script src="<?php bloginfo( 'template_url' ); ?>/js/responsiveslides.min.js"></script>

Open in new window


This is what I have on the page...
<div class="rslides-container">
				<ul class="rslides">
				  <li><img src="<?php bloginfo( 'template_url' ); ?>/images/slider/highbourne.jpg" alt=""></li>
				  <li><img src="<?php bloginfo( 'template_url' ); ?>/images/slider/6-bed-house.jpg" alt=""></li>
				</ul>
			</div><!---rslides container--->

Open in new window


and this is what I have in my footer....
<script>
  jQuery(function($) {
   $(".rslides").responsiveSlides({
  auto: false,          // Boolean: Animate automatically, true or false
  pager: true           // Boolean: Show pager, true or false
});
  });
	 
	  
</script>

Open in new window


Can't seem to get it to work at all.

Any help would be much appreciated.

Many Thanks,

Andrew
0
Hi,

How can I set a variable in JavaScript on an ASPX page but also have the contents available in the VB.NET code behind? This is for an ASP.NET 4 and VB.NET

I can set the variable in the JavaScript but it's not available in the code behind.

I can set it something like this:

 function SetUserName() {
            var myvar = document.getElementById('<%= TextBox1.ClientID %>').value
            '<%Session("LastName") = "' + myvar + '" %>';
            alert('<%=Session("LastName") %>');
        }

Open in new window


But when I try to get it from the code behind using like an Intermediate window I get like:

Session("LastName")  I like "' + myvar + '"

The alert is above in the javascript is showing the right thing. But that setting it apparently only happening on the ClientSide. How do/can I get it to happen on the client side but also on the server side or can I? Is this where Ajax come into play?

If so, how would something like that be done?

Any information would be greatly appreciated.
0
I need to build JavaScript charts ( line and bar charts) where the data is called from a SQL stored procedure. I really do not have any JavaScript developed.
Below is what I have so far....which is not completed.

   dataDailySalesChart = {
            labels: ['M', 'T', 'W', 'T', 'F', 'S', 'S'],
            series: [
                [12, 17, 7, 17, 23, 18, 38]
            ]
        };

        optionsDailySalesChart = {
            lineSmooth: Chartist.Interpolation.cardinal({
                tension: 0
            }),
            low: 0,
            high: 50, 
            chartPadding: { top: 0, right: 0, bottom: 0, left: 0},
        }

        var dailySalesChart = new Chartist.Line('#dailySalesChart', dataDailySalesChart, optionsDailySalesChart);

        md.startAnimationForLineChart(dailySalesChart);

Open in new window


The JavaScript above is hardcoded and not dynamic. I want to call the stored procedure every ten minuets to up date the JavaScript chart.
thanks
0
I successfully got this example to work on my Windows 10 pc. (thanks to help from Expert it_saige)
https://www.experts-exchange.com/questions/29039118/Running-a-Hello-World-on-Node-js-on-Windows-10-newbie.html?anchor=a42185760¬ificationFollowed=191140277#a42185760

I now want to host it on a GoDaddy hosting account I just signed up for.

I've never setup a Node.js website before - though I have worked with IIS/ASP sites for years.
Is it just a matter of copying the files to a particular folder (eg. root)?

Thanks for any help.
0
Free Tool: IP Lookup
LVL 8
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

I have a page that static-coded. Not part of Wordpress or anything. I just need to merge the first name from the URL params into the headline of the page. The url param looks like: "firstname=John".
0
I'm trying to run this example here https://github.com/squallooo/MT5 (of an HTML5 application)

It needs to run on Node.js - I am unfimilar with Node.js. (though ok with IIS)

I have downloaded Node.js and installed it. I have downloaded the ZIP file from GitHub.

Can someone please give me a step-by-step to enable me to open/run this one-page web file?

A demo is here http://mainline.i3s.unice.fr/
(pretty cool if you're a musician)

Thanks
0
Hello experts,

I've been struggling with this for some days now. I use the function below to control a youtube video embedded with an iframe. The initialize function works properly. The problem is the onPlayerStateChange function. I'm trying to control the pause and play using the same button but it doesn't seem to run properly. It doesn't pause the video and the video itself cracks or lags.

var player, time_update_interval = 0;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('videod', {
        playerVars: {
            color: 'white'
        },
        events: {
            'onReady': doThisFirst,
            'onStateChange': onPlayerStateChange
        }
    });
}

function doThisFirst(){
    updateTimerDisplay();
    clearInterval(time_update_interval);
    time_update_interval = setInterval(function () {
        updateTimerDisplay();
    }, 1000);
    $('#volume-input').val(Math.round(player.getVolume()));
}

function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING) {  // If video is playing…
              var stop = document.getElementsByClassName('playButton');
              stop[0].click(player.pauseVideo());
        }
        else{    // If video – pause
            var start = document.getElementsByClassName('playButton');
            start[0].click(player.playVideo());
        }
      }
0
I am using handlebars and ran into an issue with trying to group by a category but I was able to fix that by using underscorejs.  Now my issue is using my object categorized into arrays into my template.  Here's an image of what I see in the developer tools:
Object with two arrays
As you can see, it's an object with two arrays.  I got the data to show by doing the following but as you will see, it's not very efficient because there are actually have 6 categories and not just two.
<!-- Handlebar Js Template Starts Here -->
   
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.10/handlebars.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script type="text/javascript" src="../nrm/SiteAssets/projectMilestone.js"></script>

<script id="projectMilestone-template" type="text/x-handlebars-template">
 
<table border=1> 
 	<tr>
 		<th colspan="7">Milestones</th>
 	</tr>


	<tr>
		<td>Milestone Description</td>
		<td>Planned Date</td>
		<td>Revised Date</td>
		<td>Actual Date</td>
		<td>Type</td>
	</tr>
{{#Construction}}	
	<tr>
		<td>{{ MilestoneDescription}}</td>
		<td>{{ Planned_x0020_Date}}</td>
		<td>{{ 

Open in new window

0
Hi experts, I need to upgrade high version of excel to export html table to excel. The codes below are able to export from table to excel, How can i upgrade it to high version of excel with an extension .xlsx  ? any help please!

<!DOCTYPE html>
<html>
	<head>
		<title>jQuery Boilerplate</title>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
		<script src="dist/jquery.table2excel.min.js"></script>
	</head>
	<body>
    <button class="WinExcel">Export</button>
        <table class="Stocks32">
          <tr>
            <td>Erwin M. Malalis 500</td>
          </tr>
        </table>
<script>
	$(function() {
		$("button.WinExcel").click(function(){
			$(".Stocks32").Stocks32({
				exclude: ".noExl",
				name: "Excel Document Name",
				filename: "Prolist",
				//fileext: ".xls",
				exclude_img: true,
				exclude_links: true,
				exclude_inputs: true
			});
		 });
	});
</script>  
	</body>
</html>

Open in new window


!function(a,b,c,d){function e(b,c){this.element=b,this.settings=a.extend({},k,c),this._defaults=k,this._name=j,this.init()}function f(a){return a.filename?a.filename:"Stocks32"}function g(a){var b=/(\s+alt\s*=\s*"([^"]*)"|\s+alt\s*=\s*'([^']*)')/i;return a.replace(/<img[^>]*>/gi,function(a){var c=b.exec(a);return null!==c&&c.length>=2?c[2]:""})}function h(a){return a.replace(/<a[^>]*>|<\/a>/gi,"")}function i(a){var b=/(\s+value\s*=\s*"([^"]*)"|\s+value\s*=\s*'([^']*)')/i;return 

Open in new window

0
I have a query where I get the days of the week (Sunday - Saturday) for a week to date (so if its Monday I want Monday to Sunday of the last week) and then gives me a count of each day when that day has reported an error. Below is my example:

Today is Monday June 7th. The week to day in the query is the 7th to the 1st (Monday to Tuesday). Past 7 days
On:
Monday 7th (todays date) there were 2 errors reported
Sunday 6th there were 0 errors reported
Saturday the 5th 1 error reported
Friday the 4th 10 errors reported
Thursday the 3rd 7 errors reported
Wednesday the 2nd 0 errors reported
Tuesday the 1st 6 errors reported

Below is my attempt at the query

declare @lastweek datetime
declare @now datetime
set @now = getdate()
set @lastweek = dateadd(day,+7,@now)

select
DATENAME(dw, CAST(lm.[Datestamp] as int)) as [DayOfWeek]
from databaseTableA lm
where  lm.Datestamp BETWEEN @lastweek AND @now
		and lm.messageType = 'ERROR'
group by lm.[Datestamp]

Open in new window


Thanks for your help
This is going to be used in a javascript chart
0

JavaScript

119K

Solutions

71

Articles & Videos

41K

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.