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 have a site that has worked fine for a number of months. But something recently changed that is causing my Nav Bars to not work.

The site is:

https://makingyourlifecount.org

It works fine on one of my computers but it doesn't work on other's. I cannot figure out why the NavBars have stopped working.

If you go to the site and then scroll down until the top image disappears, the nav links then work. It's just when you scroll all the way to the top that it doesn't work.

 Any insight you can give will be helpful.

Thanks.
0
Free Tool: Subnet Calculator
LVL 11
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Need help getting this JavaScript to format with different date options like mm/dd/yyyy , mm/dd/yyyy 00:00 etc.

<%@ language="VBScript" %>
<!DOCTYPE html>
<html>
        <head>
        <script language='Javascript' runat='server'>

            function jsGetPastTimeCurrent(minutes) {
                var d = new Date();
                var past = new Date();
                past.setTime(d.getTime() + (minutes*60000));
                var utcString = past.toUTCString();
                var tz = utcString.indexOf("UTC");
                if (tz > 0) {
                    utcString = utcString.substring(0, tz) + "CT";
                }
                return utcString;
            }
        </script>
<% newDate=jsGetPastTimeCurrent(-360)%>
        <title>Timestamp</title>
    </head>
    <body>
    <p>
    <h2><%= newDate %> </h2>
    </p>
    </body>
</html>
0
Hi Experts,

Is it possible to place the cursor at the beginning when a text box receives focus?

Thank you
0
Hi,

I have an excel sheet with a macro that merges two other sheets into one.  I would like to take that VBA and call it from a .cmd or something like that.   I need an external ETL tool to be able to call it and the ETL tool can call javascript or .cmd


Can you call VBA outside excel.  Excuse my ignorance but I know very little on the subject.

Thanks
0
Hi,
Within Javascript below, I cannot update value into tb_pass. Why?
                    var name = this.$content.find('.name').val();
                    var newname = this.$content.find('.newname').val();
                    var status = this.$content.find('.status');
                    if (name == "") {
                        $.alert("Invalid password and please enter one valid password!");
                        return false;
                    }
                    if (name == newname) {
                        // status.val(scorePassword(name));
                        //$.alert('Valid Password is entered!');
                        var pass_val = document.getElementById("tb_pass").value;
                        pass_val = name;
						...
                <asp:Textbox ID="tb_pass"
                    width="310px"
                    Style='display:none;visibility:hidden;'
                    Font-Names="標楷體" 
                    Font-Size="11pt" 
                    Font-Bold="true"
                    ForeColor="Black"
                    runat="server" />
					...

Open in new window

0
i have select element on my page

<select id="Sort By" class="form-control" style="width:250px;">
                        <option>Select One</option>
                        <option value="1">Star Rating (1-5)</option>
                        <option value="2">Star Rating (5-1)</option>
                        </select>

Open in new window


i need to search in data twice if change to val 1

$sqlpackages="SELECT * FROM packages ORDER BY Package_Price ASC ";

if change to val 2

$sqlpackages="SELECT * FROM packages ORDER BY Package_Price DSC";
0
I have a script that is popping a window (uglipop) from vb code

ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "script", "$(document).ready(function () { custom1(); });", True)

On close of that window how do I reload the current page?
0
I have a child page inheriting from a master, there are 2 buttons on the page. One for printing the contents of a div, and the other for exporting the contents of a div to MS Excel.

Clicking the Excel button works fine every time until I click the 'Print' button (which works every time), after that I get the form is not connected error.

Doing the same on a 'non-master/child' page does not produce the error, so obviously it has something to do with the form element residing on the master.

Here is the mark-up:

<%@ Page Title="" Language="VB" MasterPageFile="~/main.master" AutoEventWireup="false" CodeFile="FormTest.aspx.vb" Inherits="FormTest" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    EXCEL PRINT TEST
    <br />
    <asp:LinkButton runat="server" ID="cmdExport" CssClass="btn btn-info">Export to Excel</asp:LinkButton>
    <br />
    <input name="b_print2" type="button" onclick="printdiv('divPrint');" value="Print" />
    <br />
    <div runat="server" id="divExcel">
        <div id="divPrint">
            <br />
            Print and export content here
        </div>
    </div>

    <script type="text/javascript">

        // =========================================
        // Function to print the contents of a DIV
        // =========================================

        function printdiv(printpage) {            
    

Open in new window

0
I have a modal div on a view, with a textbox and a button.  here is the javascript for the button click:

    $("#Search").on("click", function (e) {
        e.preventDefault();
        var address = $("#txtSa").val();
        var sa = address.replace(/ /g, "-");
        var frmData = new FormData();
        frmData.append("StreetAddress", sa);
        var url = "/Residents/SearchAddress"; ///" + sa;

        $.ajax({
            type: "POST",
            url: url,
            data: frmData,
            success: function (response) {
                alert(response);
            }
        });
    });

Open in new window


When this code executes I get the following script error:
jquery-3.1.1.js:8400 Uncaught TypeError: Illegal invocation
    at add (jquery-3.1.1.js:8400)
    at buildParams (jquery-3.1.1.js:8387)
    at Function.jQuery.param (jquery-3.1.1.js:8420)
    at Function.ajax (jquery-3.1.1.js:9010)
    at HTMLButtonElement.<anonymous> (Index:361)
    at HTMLButtonElement.dispatch (jquery-3.1.1.js:5201)
    at HTMLButtonElement.elemData.handle (jquery-3.1.1.js:5009)
add @ jquery-3.1.1.js:8400
buildParams @ jquery-3.1.1.js:8387
jQuery.param @ jquery-3.1.1.js:8420
ajax @ jquery-3.1.1.js:9010
(anonymous) @ Index:361
dispatch @ jquery-3.1.1.js:5201
elemData.handle @ jquery-3.1.1.js:5009

Open in new window


I am calling a controller action below, but it never reaches the controller:
[HttpPost]
        public ActionResult SearchAddress(string StreetAddress)
        {
            string result = "no";

            string address = StreetAddress.Replace("-", " ");

            Resident res = db.Residents.AsNoTracking().Where(r => r.StreetAddress.Equals(address)).FirstOrDefault();

            if (res != null)
            {
                result = "yes";
            }

            return Content(result);
        }

Open in new window


I don't know what I'm doing wrong here.
0
i am doing like page northguru.com

page name is packages

it has a javascript code which make like that :

we have div call it container included buttons all buttons when click show hidden div call it sub explain what they mean or have all sub div shows in the same  container

i did this all
2.jpg1.jpgthe problem is :

i have data repeated from sql good and sub data brings good but when press any button to show sub only the first container subs shows why ??
0
What does it mean to be "Always On"?
LVL 5
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Hi Experts,

I am self-employed, and mostly dealt with small clients, whom I charged around $35 per hour.

Now I am trying to break through Corporations, Municipalities (Toronto), provincial and federal contracts. What would be the normal hourly charge I should account for when pricing out projects?

The areas that I specialize in are PHP, MySQL, HTML5, CSS3, JS, jQuery, (Classic ASP, MSSQL, VB 6 and Access.) - those in brackets are just for legacy support.
0
Look for simple way to get city and state by provide zip code.
I have HTML form thanks
0
Given  the following code segments:
  lookupEvents={
    "/responsive/lead-form.":"event19",
    "checking-offer":"event29",
    "checking-offer-confirmation":"event32"
  };
...
 __.map(lookupEvents,function(value,key) {
            if(pathname.indexOf(key)!==-1) {returnValue.push(value);}
}

Open in new window


Is there a way to use a regX or other approach, possibly _filter, so both event29 and event32 are not set for URLs containing "checking-offer-confirmation"? I only want to set event32 for  "checking-offer-confirmation". I'm new to Underscore so not quiet sure how to handle this particular situation?

Thanks!
0
I have simple html form allow to enter zip code. my goal is if the user put 5 digital there, and it will populate
list of city in <div id=cityList></div>, and when <div> has value</div> then I can click on city, and populate the selected city
into another textbox <input type="text" id=city>

How can I do that in javascript?
0
I have the following example which I'm using for PowerShell. I need to use inverted commas and I'm unsure how to achieve this?

If I leave the following '" + a + "' then it results in 'variable' or in this case, 'username'
If I remove the apostrophe, i.e. " + a + " it results in the variable without the inverted commas
if I double the inverted commas, i.e. "" + a + "" the script fails to run

I need the output of a to present as: "variable" or in this example, "username" not 'username'

What am I missing?

<style>
 body {background-color: white;}
 a {color: yellow; font-size: 14px;font-family: verdana; background-color: navy;}
 define {color: navy; font-size: 13px; font-family: verdana; font-weight: bold;}  
 example1 {color: navy; font-size: 12px; font-family: verdana;}
</style>
<script>
function myFunction() {
    var a = document.getElementById("a").value;


//Get User Properties - Brief	
	pText = "<span style='color: grey;font-size: 75%;font-family: verdana;'>Get-ADUser '" + a + "'</span>";
//Get User Properties - General
	pText = pText + "</br><span style='color: grey;font-size: 75%;font-family: verdana;'>Get-ADUser '" + a + "' -Properties *</span>";
	document.getElementById("Powershell").innerHTML = pText
//Get User Properties - All	
	pText = pText + "</br><span style='color: grey;font-size: 75%;font-family: verdana;'>Get-ADUser '" + a + "' -Properties * | Select *</span>";
	document.getElementById("Powershell").innerHTML = pText
}
</script>
<body>

Open in new window

0
if button 1 is clicked  one div will be shown if 2 is clicked 2 divs will be shown if 3 is clicked 3 divs will be shown,  so if button 1 is clicked the div should take full width  if button 2 is clicked it shows 2 divs  and it should share the full width. and if the button 3 is clicked it should share the width according.  finally how to share the width automatically for divs.
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script type="text/javascript"></script>
	
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	
	<style type="text/css">
	#one , #two , #three{border:1px solid #cccccc;
		width: 32%;
		height: 500px;
		display: inline-block;
		
	
	}
	
	</style>
	<script>
$(document).ready(function(){
$(".button1").click(function(){
$("#one").toggle();

}); 
$(".button2").click(function(){
$("#two , #three").toggle(); 
});
$(".button3").click(function(){
$("#one , #two , #three").toggle(); 
});
}); 
	</script>
</head>
<body>

	<div class="container" style="border: 1px solid red;width: 100%; height: 100%;">
		<div class="contan" id="one" style="display: none;">

			1st container
			
		</div>
		<div  class="contan" id="two" style="display: none;">

			2nd container 
			
		</div>
		<div  class="contan" id="three" style="display: none;">

			3rd container
			
		</div>
		

		


		
	</div>
	<input type="button" class="button1" name="" value="button1" />
	<input type="button" class="button2" name="" value="button2" />
	<input 

Open in new window

0
In our office the website https://barefruit.com.au/ is working for everyone except one computer user.  A Mac.  No watter what browser used, the video doen't play, just an image.

Can anyone give me an idea as to why this might be happening?
0
How can I check all checkboxes using the "Select All" checkbox from below please?

                    <ul class="list-group">
                        <li class="list-group-item" style="font-weight: bold;"><input type="checkbox" name="select_all" id="select_all">&nbsp;Select All</li>
                        <%For i = 0 To UBOund(PackMmbrs, 2) - 1%>
                                <li class="list-group-item">
                                    <input type="checkbox" name="select_<%=PackMmbrs(0, i)%>" id="select_<%=PackMmbrs(0, i)%>">
                                    <%=PackMmbrs(3, i)%>, <%=PackMmbrs(2, i)%>(<%=GetTeamName(PackMmbrs(4, i))%>)
                                </li>
                        <%Next%>
                    </ul>

Open in new window


Thank you!
0
Hello
I have set a general cookie that works fine for a run once situation. However, what I need to do is set a cookie by username so a message is displayed only once per user.

I have posted the code I am using for the general cookie and wonder if it can be modified to target a username rather than a general cookie. I am using php to set a session for the username linked to mysql.

I would be grateful if someone could help with this. Thanks

<script>
$(document).ready(function() {
  if (document.cookie.indexOf("runOnce") < 0) {
    $("#message3").dialog({
      modal: true,

      buttons: {
        'Confirm': function() {
            document.cookie = 'runOnce = true; expires = Fri, 31 Dec 9999 23:59:59 GMT; path = /';
            $(this).dialog("close");
          }
          /* ,
          No: function () {
          $( this ).dialog( "close" ); 
          }*/

      }
    });

    // Hide the close button
    jQuery("a.ui-dialog-titlebar-close").hide();

    //Disable the confirm button on page load
    $(":button:contains('Confirm')").attr("disabled", true).addClass("ui-state-disabled");

    // Uncheck the 'agree' checkbox
    $(function() {
      $('#message3 input[type=checkbox]').attr('checked', false);
    });

    // Hide red message paragraph
    $('#agreemsg').hide();

    // Function to enable and disable confirm button based on checkbox click event
    $("#checkme").click(function() {

      var isChecked = $("#checkme").is(":checked");

      if

Open in new window

0
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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!

I am developing an app with Electron and need to display a message box to the user. This is the code I have:

const   electron = require('electron')
const   dialog = electron.dialog

        dialog.showMessageBox(BrowserWindow, {
            type: "info",
            buttons: ["OK", "Cancel"],
            title: "Importer Finished",
            message: "All done",
            detail: "Open you imported project in the IDE"
        }, resp => {

        })

Open in new window


The message box displayed does not follow the options, see the attached snippet.

I hope someone can point me in the right direction to fix this, thanks,
Sid
a-1.PNG
0
Hi Experts,

I have the following code, which works when the documents first loads
$(document).ready(function(){
    
    //Display App't Setter
    $('#aApptSetter').on('click', function(){
       //$('#divNextAppt').css('display', 'none'); 
       $('#divApptSetter').css('display', 'block');
    });
});

Open in new window


However, after I fire the below, the above no longer reacts?
function updateAppt(data){
    
    var gmail_id = data.event_id;
    var appt = data.date + ' at ' + data.time;
    
    var html = "";
    html += "<label>The next appointment for this client is <b>" + appt; 
    html += "</b> Click <a id=\"aApptSetter\">here</a> to change.</label>";
    
    $('#divNextAppt').html(html);
    $('#gmail_id').val(gmail_id);
    
    $('#slots').children().remove();
    $('#weeks').children().remove();
    
    $('#divApptSetter').css('display', 'none');
}

Open in new window


When the document loads, the  original HTML is
<div id="divNextAppt">
                
                                    <label>No upcoming appointments for this client.
                            Click <a id="aApptSetter">here</a> to set.</label>
                    
            </div>

Open in new window


Any help will be appreciated.
0
Hi,
I am trying to put a once per session script on a site was done on bootsrtrap4 for a modal pop up. I tried with two different scripts, unfortunately, none of them worked. I am a newbie in JS. I tried all I knew.... The scripts were copied from net, I have just adapted to my needs.
Script 1 opens automatically and closes automatically
<script>
jQuery(document).ready(function () {
    // Get saved data from sessionStorage
    var visited = sessionStorage.getItem('visited');

    setTimeout(function () {
        if (visited !== true) {
            $('#exModal1').modal('show');
            sessionStorage.setItem('visited', true); // Save data to sessionStorage
        } 
    }, 2000);

});
  setTimeout(function() {
    $('#exModal1').modal('hide');
}, 20000);
</script>

Open in new window

Script 2 opens and closes automatically
<script>
	   $(document).ready(function() {
	    $(function() {
  if (typeof Storage != "undefined") { //I put visited here, not working....
    if (!localStorage.getItem("done")) {
    
   setTimeout(function(){
       $('#exModal1').modal('show');
   }, 2000);
    setTimeout(function() {
    $('#exModal1').modal('hide');
}, 20000);
    localStorage.setItem("done", true);
  }
});             
   
</script>

Open in new window

and html for pop up modal is
  <!-- Modal page onload start-->
<div class="modal fade" id="exModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">×</span>
        </button>
      </div>
      <div class="modal-body" id="anim1">
        Your text ...bla bla... and so on!
      </div>
      <div class="modal-footer">
            <span id="timer"></span><!-- timer-->
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      
      </div>
    </div>
  </div>
</div>
   <!-- Modal page onload end-->   

Open in new window

0
Hi everybody.
Checking PageSpeed tool I'm a bit confused about inconsistent results.
For my pages I have a simple basic structure like the one below
<!DOCTYPE html>
<html lang="en">
	<head>

		<?php require_once "inc_head.php" ?>

	</head>
	<!--/head-->

	<body class="homepage">

		<header id="header">
			<?php require_once "inc_topbar.php" ?>
			
			<?php require_once "inc_nav.php" ?>
			
		</header>
		<!--/header-->

		<section id="content">
			<!--page content here-->
		</section>

		<section id="feature">
			<div class="container">
				
			</div>
		</section>
		
		<?php require_once "inc_footer.php" ?>
	</body>
</html>

Open in new window


So what I exepect to get as Pagespeed result is something inherent to the section "content". Once I have already optimized Head and footer sections, I shouldn't receive warning about "render-blocking JavaScript and CSS" because they are the same for all my pages.

As a side note, I'm using CloudFlare to serve my files, so I purged the cache in CloudFlare panel in order to get updated results in PageSpeed, but it still tells me the same thing...

Any idea?
0
Hi everybody.
I've finally decided to face the annoying problem of SEO optimization. I'm using PageSpeed Insights and there are some things which are confusing me a bit.

The one I want ask about here is this: PSI tells me to Eliminate render-blocking JavaScript and CSS in above-the-fold content; I've put anything but bootstrap.min.css in the footer but I still receive the same message. I've put even bootstrap.min.css in the footer and not only I've got a horrible effect loading page (it appears without any css attached for a fraction of second) but the message is still here.

They suggest to optimize CSS delivery. If I understand correctly, I should have to extract from bootstrap the essential rule to give my page a decent aspect and the using the suggested javascript (https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery) function to defer the loading of the rest of the css. Is this correct?

Thank you
0
I'm trying to figure out if different browsers will return different messages/errors when a string is passed into a date function as per the below example where last[0] = "new visit":

var lastVisit = new Date(last[0]);

Open in new window


Chrome returns "Invalid Date" but not sure how robust this will be across all browsers if I'm using:

if(lastvisit != "Invalid Date")

Open in new window


I'm not sure if there is a better way to detect if I got a date format back or an invalid date? I can't do anything about the string being passed. It will happen the initial session a user hits the site.
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.