JavaScript

120K

Solutions

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 am developing a around 300 HTML web pages that need a version number displayed in the footer. Problem is some customers are using version A and some people are using version B. So depending on the user, I want to display A or B and only want to change it in one place. I have used document.write and pointed to a .js named ver.js file which contains

document.write('Test: V4.5')

Open in new window



and the HTML to display on the page:
<script language="javascript" type="text/javascript" src="ver.js"></script> 

Open in new window


My question is, if I have three different versions I need to display depending on the user, what is the best method to display ('Test: V4.5') or ('Test: V4.6') or ('Test: V4.7') using  JavaScript which would be written in one place. I don't want to have to hand write the version number on each page, but only in one spot. I asked this question on Stack Exchange and got beat to hell by those who answered. Can you guys help? I am trying to learn this and hope I am asking this question the right way.

Further, lets say user ONE should see Version 4.5 on the bottom of their page, and user TWO should see Version 4.8 at the bottom of the page. And since I have 300 pages, I only want to change the version in one place to be reflected on all 300 pages?

I know I can use Variables, but not sure the correct way to do this. I am not using PHP.

Thank you for not yelling at me.
0
Never miss a deadline with monday.com
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

I have a simple Mega Menu. I am trying to display the sub menu of the parent menu item clicked. But for some reason when I click the parent item all the sub menu's are displaying instead of the clicked parent item sub menu. What I am doing wrong.

Here is my JSFiddle link

https://jsfiddle.net/jokcLjkb/4/

here is my js code i am using

$(document).ready(function() {
    $("a.drop").on('click', function(e) {	
        e.preventDefault();
        $("ul.mainNav li > .drop-full-col").css("display","block");
    });
});

Open in new window


Thanks and Appreciate it
0
Hi Guys,
I have a question regarding a JSON data.
Let's say I have two arrays:
  var headers = [
      "header1",
      "header2",
      "header3",
      "header4",
    ]

    var data = [
       ["data1", "data2", "data3", "data4"],
       ["data1", "data2", "data3", "data4"],
       ["data1", "data2", "data3", "data4"],
       ["data1", "data2", "data3", "data4"],
       ["data1", "data2", "data3", "data4"]

    ]

Open in new window

now what I want to do is, for each data row I want to assign header and I want the result as it below:
[{"header1": "data1", "header2": "data2", "header3": "data3", "header4":"data4"}, ]

Open in new window


And do it for all 4 rows.

I was trying something like below which didn't work:
 function tst() {
        debugger;
        jsonarray = [];
        for (var i = 0; i < data.length; i++) {
            for (var j = 0; j < headers.length; j++) {
                var insert = "{" + headers[j] + ":" + data[i][i] + "},"
                jsonarray.push(
                    insert
                );
            }
        }

Open in new window


Please, advise.
Thank you.
0
hello, iam trying to do a video player project for that i would like to keep like buttons and i have did that for all videos in only one single page but my problem is i kept one id for all videos  calling function for all videos but while im hitting like button it is counting for only one video like button not for another like button please help me
<html>
<head>
<script>
var Clicks = 0 ;
function AddClick(){
Clicks = Clicks + 1;
document.getElementById('CountedClicks').innerHTML = Clicks + ' Hits';
}
</script>
</head>

<body>
<button id="CountedClicks" type="button"></button><br>
<button style="background-color:green" >Count Your Hit</button>
<br>
<button id="CountedClicks" type="button"></button><br>
<button style="background-color:blue" onclick="AddClick()">Count Your Hit</button>
</body>

</html>

Open in new window

0
Not sure where to begin, I am using a CSV to Html table template by Derek Eder https://github.com/derekeder/csv-to-html-table.
Chris Stanyon pointed out that it appears to be using the DataTable plugin on a previous related question of mine
Is there a way to format the table so a if column 5 has CANCELED anywhere in it it makes the entire row black with white text
I don't have any experience in javascript as is apparent from my previous question so any help would be greatly appreciated.
0
Not sure where to begin, I am using a CSV to Html table template by Derek Eder https://github.com/derekeder/csv-to-html-table.
I'm using it to display a list of events that have happened, I would like to see if there is a way to make the default sort for the java app be reverse chronological order instead of chronological order. I know there are multiple sort functions, however since I am automatically refreshing every 10 seconds and it would be handy to have the results sorted the way I would like automatically.
I don't have any experience in java so any help would be greatly appreciated.
0
Hi Experts,

I've been using a JS export code that allows me to take data that is being passed from my dashboard and exported as a new excel file (xls).  The export function allows you to save the name of the file, and sheet name.  All this is great.  What I am needing help on is how can we programmatically save the exported file to a pre determined folder (network drive)?  I am not familiar with JavaScript so any assistance would be greatly appreciated.  

This is a request that will give executives the ability to click on a report used for certifying data and have to only hit "Certify" and the csv is placed in a network drive (folder) and the executives will never have to do anything other than hit the certify button. The problem with my code now is that it saves on the local machine as a default.

https://github.com/jmaister/excellentexport

Thanks!  
Attached
excellentexport.js
0
I'm trying to figure out how I can scrap/detect if the phrase "We regret we cannot open the account you requested." is on the page using CSS Selector and/or Javascript (jQuery is ok if that is the only option but want to avoid it if possible?). Below is an excerpt from the mark-up.
<!-- current page: offers --> 
        <div class="main">
     <h3>Eligibility Results</h3><p>Thank you for your online application for an account at Bank of the West.  We regret we cannot open the account you requested.<br/>
If you would like to discuss this application with Bank of the West, please contact us at:</p>

Open in new window


Thanks!
0
Need to show or hide a DIV with Javascript based off of PHP string variable. Basically, I have a DIV with a lot of information and do not want to show it on the page, if the information supplier with the PHP script has not values. I am testing the value by setting a php variable and want to use javascript to see if there is a string in the php variable and if so, show the div. If the string is empty or blank, then hide the DIV.
0
I'm working on a web site with a search box that shows the search results in an overlay with the original page unavailable in the background. I need to change the focus to the first link in the search results box so that visually impaired people using an OCR will hear or feel the brail of the first search result. (Currently the OCR continues to read from the page behind.)
The search uses www.googleapis.com/customsearch as the search engine.
After the search completes, one of the <div> tags gets an extra class: The <div> goes from :
<div class="gsc-results-wrapper-overlay" >
to
<div class="gsc-results-wrapper-overlay gsc-results-wrapper-visible">
That gsc-results-wrapper-visible class gets added to the div tag.
The page is created with SharePoint and so I don't want to mess with that unless there is no other choice. I want to do everything on the client side if possible.
My question is, how can I capture that div element when the search finishes. What DOM event would I react to? More generally, how can I discover these DOM events myself using developer tools?
I thought about something like this:
document.getElementsByClassName("gsc-results-wrapper-overlay").addEventListener("eventX", displayDate);
But even then I don't know what "eventX" would be.
The site is here:
https://www.dcccd.edu/pages/default.aspx
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I have a script that paginates pages in a table, which works fine. I also have a dropdown to select how many records to show in the table. Although this works, if I select say 20 records the pagination does not update to reflect the change.

When the table is run, the default records to show is 8 whih makes 9 pages. But if I select 20 in the drop down it still says 9 and if I go to page 9 it is obviously empty. I am also wondering if it is possible to have the script appear in both before and after the table. the reson for this is if a user gets to the bottom of say 100 records, then I would like this feature so they don't have to go all the way back to the top.

I would appreciate any help as my javascript is not 100%. Many thanks

php

<?php
    echo "<table class='paginated' cellspacing='0' cellpadding='0'>";
    echo "<div class='pager'></div>";
    echo "<thead><tr><th style='width: 5%;'>#</th><th>Service</th><th>Activity</th><th>Dept</th><th>Company</th><th>Address</th><th>User</th><th>Item</th><th>Date</th><th style='width: 19%;'>Action</th></tr></thead>";

    while($row = mysqli_fetch_array($result)){

    $id = $row['id'];
    $service = $row['service'];
    $activity = $row['activity'];
    $dept = $row['department'];
    $company = $row['company'];
    $address = $row['address'];
    $user = $row['user'];
    $box = $row['item'];
    $date = $row['date'];
    $date = date('d-m-Y h:i:s', strtotime($date));
    $edit = "<button type='button' class='btn

Open in new window

0
hi
i have end dates that are stored in the database as: February 15, 2018 10:9:29

one is created from edge browser, one from chrome and one from FF. all of them are stored with the same string.
but all these browsers interpret the date differently. i attach the console images:
edge interpret all of them.
chrome and FF see the one that was created with edge as Invalid Date
also, FF interpret the date differently than chrome.

the aim is to delete the record if the date and time has past. so i have this:
let today = new Date();
console.log('today: ',today);
          data.forEach((data) => {

            if( new Date(data.enddate) < today  ){
              //delete automatically hangouts which are past due date
              console.log('in the past: ',new Date(data.enddate));
              this.deleteSelfieChallange(data.$key,data,false);
            }else{
              console.log('not in the past: ',new Date(data.enddate));
            }

          })

Open in new window


the issue is that the deletion obviously does not work with the Invald date.

any idea?
from chromefrom edgefrom FF
0
Hi I am trying to get my games to output the current time in seconds that the game is running for as a score for the player in the canvas but I keep getting an undefined var instead of the number?

Does anyone have any idea whats wrong with my code??


Thanks, See code below.

HTML5 Canvas
JS
var Game = {
    canvas : undefined,
    ctx : undefined,
    backgroundImage : undefined,
    backgroundMusic :undefined,
    soundImage: undefined,
    soundImagePosition : { x : 750, y : 10 },
    vy : 0,
    rocket : undefined,
    rocketPosition : { x : 350, y : 400 },
    dxSpeed: 7,
	dySpeed: 3,
	keyboard : { keyDown : -1 },
	keys : {
    A: 65,     B: 66,      C: 67,      D: 68,       E: 69,      F: 70,
    G: 71,     H: 72,      I: 73,      J: 74,       K: 75,      L: 76,
    M: 77,     N: 78,      O: 79,      P: 80,       Q: 81,      R: 82,
    S: 83,     T: 84,      U: 85,      V: 86,       W: 87,      X: 88,
    Y: 89,     Z: 90, 	   LA:37,      UA:38, 	    RA:39,      DA:40,
 }
};

function handleKeyDown(evt) {
    Game.keyboard.keyDown = evt.keyCode;
}

function handleKeyUp(evt) {
    Game.keyboard.keyDown = -1;
}

Game.start = function () {
    
    document.onkeydown = handleKeyDown;
    document.onkeyup = handleKeyUp;

    Game.canvas = document.getElementById("myCanvas");
    Game.ctx = Game.canvas.getContext("2d");
  

    Game.backgroundMusic = new Audio();
    Game.backgroundMusic.src = "assets/audio/start.mp3";
    

Open in new window

0
Hi Guys,
I am returning JSON data from the server with ajax. When the data return it come like:
"['Id','Name','Phone','MailStop','Active','Out','UserName','RowTimeStamp','UserId','EmailAddress','FirstName','LastName','SSN','StatusStatus',]"

The issue I have here is the quotation in the beginning and the end. I do I remove these quotations. I have to take this data above and make it like a string.
I was trying many things like stringify, replace.
please see my code example:

function GetData() {
        var data;
        $.ajax({
            type: "GET",
            url: '/Tables/Getpaging',
            dataType: "json",
            async: false,
            //data: {},
            success: function (resp) {
                data = resp
            }
        });
        return data;
    }

    var Dataobj = GetData().BindData;

function GetHeaders() {
        var headerName = "";
        for (var i = 0; i < Dataobj.length; i++) {
            if (i == 0) {
                for (var key in Dataobj[i]) {
                    headerName += "'" + key + "',";
                }
            } else {
                break;
            }
        }
        debugger;       
        var arr = "[" + headerName + "]";
        return arr;
    }
    

Open in new window

0
Hello,

Can anyone remind me how to disable right-click using JS/jQuery?

Also, although doubtful, as I'm working with sensitive data, is it possible to disable copying, highlighting, Ctrl+C,Alt+Print Screen, and other methods of replicating the data?

Thank you..
0
I had this question after viewing Extracting text from a lookup field in a SharePoint 2013 workflow.

My issue is that I have three lookups.  They are creating a cascading drop down.  The problem is, to make the Cascading Drop Down work, I have to add the ID of the first list.  So even though the Display on my form does show the Titles the value that is passed is an integer.  Any thoughts on how to capture the text values rather than the underlying ID values?  I am also using an InfoPath form for my form.

-- No responses so I will clarify for simplicity.  
  - Lookup 1 (ID and Title)
  - Lookup 2 (ID, Title, Title from Lookup 1)
  - Lookup 3 (ID, Title and Title from Lookup 2)

This works find for three drop downs on my form.  The issue is when the record is saved, the value (ID Integer) of each lookup is saved rather than the DisplayName.  I'm trying to capture the DisplayName so I can pass it to another list.  I know how to pass the field values, but again, I'm not looking for the ID value, I want to DisplayName value.  I have seen it done with standard forms in SharePoint Designer using Javascript, but I am using Infopath Custom forms. You will see from the image that where EIS Part is the selector.  The field I want to fill is EIS Part A.  Instead of getting the longer text in EIS Part to display in EIS Part A, it shows the ID which is 2. Snipaste_2018-02-13_12-24-41.png
0
Hi,

I have this page:
https://kroweb.dk/gfdev/arkivalier/ft_6/

I use a DataTable on the page to present search results.
At the top-left of the DataTable I am showing the Info block and at the top-right the Search block.
My problem is that both blocks are mis-functioning in a strange random-like way.

The Info block counts wrong - sometimes it says 1 of 1 entries when there are 200 entries and sometime it says 12 of 12 entries when there are 47 entries. It looks a little like it is random what it says.
The searchblock is not reducing the results according to text entered in the Search field. I t also seems a little random what it actually do.

I Have DataTable working on many of my other pages without any problems, and I can't figure out what is wrong here.

I have this code in the head of my main file:
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
    <link rel="stylesheet" type="text/css" href="../../templates/template_style.css"> 
    <link rel="stylesheet" type="text/css" href="style.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css" />
    
    
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script 

Open in new window

0
In this example, they are using a JavaScript function to get the host name of the page.

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_loc_hostname


Is there a way to do this exact same thing using jquery ?
0
I am really confused as to why my code is not working. Here is the problem and my code below.
----------------------------------------------------------
The class Puppy needs two methods.

The getsTreat method should accept one parameter. It should increase happiness by 20 for each treat received, then return the new happiness value.

The takesNap method should decrease energy by 45 and increase behavior by 15.

Make sure you make the puppy take his nap in order to change his energy and behavior levels.
--------------------------------------------------------
class Puppy {

  constructor(happiness, energy, behavior) {
    this.happiness = happiness
    this.energy = energy
    this.behavior = behavior
  }
 
  // code here
  getsTreat(num){
    return this.happiness + num * 20;
  }
 
  takesNap(){
    this.energy - 45;
    this.behavior + 15;
  }
}

var Charles = new Puppy(75, 25, 30)
Charles.takesNap()
Charles.getsTreat(4)
Charles
0
The new generation of project management tools
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Hi E's,
I try to get a solution for send via Jquery ajax a object and a variable at the same call.
This is the code I have when the data is one object:
var file_data = $('#imagem').prop('files')[0];    
                    var form_data = new FormData();                  
                    form_data.append('file', file_data);                            
                    $.ajax({
                        url: 'ajax_upload.php', 
                        dataType: 'text',  
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: form_data,                         
                        type: 'post',
                        success: function(php_script_response){
                            alert(php_script_response); //
                        }
                    });

Open in new window

In above code "form_data" contain the information of a upload file.
My problem is, I have a simple variable to send in the same call, and usually when I send variables I use "data" like this: data: {"var":value},.
But I don't know send both, object and variable.
I need some solution that send both things, like this: data: {"var":valor, "var":valor},+form_data;

Can you help me please?!

The best regards, JC
0
Hello

I need what I think is a media query that will sense when an incoming web visitor is using a cell phone or tablet -- and then will automatically redirect them to another web page in the same domain.

Thanks!
Rowby
0
Hi everybody.
I have a problem with PHP sessions.
I have developed a backend for a mobile app developed by another team of devs. The app send requests to my php scripts which collects data and send them to the mobile app.
The problem is that I have used PHP sessions and this way, if the mobile app doesn't send requests for 30 minutes, the session expires and the php scripts return bad or null values.

I have now to manage this issue and I'm wondering what is the best way to do it. Can I set the php.ini in order to make sessions never expire? Or do I have to tell developers to use Ajax to prevent session expiring? Or there is some better way?

Thanks for any suggestion :)
0
I have a JS Code which goes to a new site upon click or/and enter. I would like to the new site to open in a new tab or window. Right now it is opening in the same window. I have tried adding window.open(" ") around my links, but that didn't work. Also use of iframes is not allowed. Your help is greatly appreciated.
0
<div class="product-price"><span class="price"><strike>349,00&nbsp;</strike></span>49,00&nbsp;<span class="currency">DKK</span></div>

How does I find 49,00 ?
I can´t change the DOM, so I need to find it due jQuery.
0
I have a folder full of images (with specific quotes in them) that I would like to randomly swap out on page load.  Not sure the best way to get this done.
0

JavaScript

120K

Solutions

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.

Vendor Experts

Gil FeldmanMonday Learn more about Monday