Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

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

Hello

I am learning node and the node package manager. I understand the npm is to install libraries and packages etc. I understand node.js runtime is what will execute the javascript code but in the tutorial I am following it says to do this

npm install -g npm

This is installing the npm package according to the guide. What is the npm package?

Ive read these pages:
https://www.npmjs.com/
https://www.npmjs.com/package/npm

The first page gives common packages which people install, one of which is npm, a javascript package manager

I thought i had already installed the node package manager with node? Please can you explain the difference between the npm command line tool and the npm package you install with it?

Many thanks
0
Hi,
I cannot show datepicker, using the below codes. Why?

            $("#tb_birth").datepicker({
                dateFormat: "yy-mm-dd",
                changeYear: true,
                showOn: "button",
            }).next('button').text('').button({
                icons: {
                    primary: 'ui-icon-calendar'
                },
                label: "Select a date",
                text: false
            })
            ...
                <asp:TextBox ID="tb_birth"
                    width="310px"
                    Enabled="false"
                    class="Datepicker"
                    Font-Names="標楷體" 
                    Font-Size="13pt" 
                    Font-Bold="true"
                    ForeColor="Black"
                    runat="server" />

Open in new window

0
how i can make search in another page and take form values to search page

if there is another suggest i listen
0
I have tied a java script function to a custom validator.  I've also attempted to wire the function to fire when a button is clicked, and that appears to work when I step through my code. What I'm attempting to do, is to stop the processing of the code, in my on click event, if the validation fails. For example, in this case, if the value entered is less than or equal to 3 digits in length then I want the page to display an alert saying so, but I also want the code in the on click event to stop at that point. How do I achieve this?

javascript:

                            function ValidateSearchTxt(source, args)
            {
                args.IsValid = true;
                var val = args.Value;
                $("#cmdSearch").click(function () {
                    if (!(isNaN(val)))
                    {
                        if (val.length <= 3) {

                            alert('<%Response.Write(GetDisplayString("text.donors.ePassportScheduledEventList.VldSearchTxt"));%>');
                            args.IsValid = false;
                        }
                        else {
                            args.IsValid = true;
                        }
                    }
                });
            }

HTML:

 <asp:CustomValidator runat="server" ID="vldSearchTxt" Display="None" ControlToValidate="txtSearchText"  ClientValidationFunction="ValidateSearchTxt" ErrorMessage="vldSearchTxt" />

C#:
        protected void …
0
I'm breaking down some code that I didn't write so I can better understand it and JQuery in general.

Here's the form validation function...

function validateForm() {
	var dob = document.getElementById("usrDOB");
	var usrSSN = document.getElementById("usrSSN");
	var error = '';
	if (!isValidDate(dob.value)) 
	{
		$('#usrDOB').css('border', 'solid 2px red').focus();
		error = "Date of Birth must be in the format XX/XX/XXXX\n\r";
	} 
	else 
	{
		$('#usrDOB').css('border', '');
	}
	
	[b]if (!isInt(usrSSN.value)) [/b]
	{
		$('#usrSSN').css('border', 'solid 2px red').focus();
		error = error.concat("SSN must be numeric\n\r");
	}
	else
	{
		$('#usrSSN').css('border', '');
	}
	
	if (error.length > 0) {
		alert(error);
		return false;
	}
	return true;
}

Open in new window


My question is with "isInt."

Here's that function:

function isInt(value) {
    	return !isNaN(parseInt(value, 10))
			&& (parseFloat(value, 10) == parseInt(value, 10));
}

Open in new window


I saw from some "googling," that "isNan" is a built in JQuery function. I'm just trying to figure out the logic of what's there.

 return !isNaN(parseInt(value, 10))
&& (parseFloat(value, 10) == parseInt(value, 10));

I want to be able to explain to someone in plain English what's happening and I'm stumbling.

"parseInt" is going to trim any superflous text from the value that's being passed into the function and focus on the integer that's present (https://www.w3schools.com/jsref/jsref_parseint.asp). But what's "10?"

parseFloat is looking at a number and reducing it to a prescribed number of decimal places.

So, going back to the original function, it looks as though it's wanting an equality to exist between what's being parsed and what's being floated, but I don't understand "10" and it looks as though the function is set up to return a "false" value.

What is this doing?
0
i am not good in java

i have this code

i need to insert one value in the first input and auto calculate in the second and third input

<input type="text" name="markup" id="markup">
<input type="text" name="mark" id="mark">
<input type="text" name="marknet" id="marknet">

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
      $(document).ready(function(){
                                          
            var item1=$("#markup").val() / 100 ;
            var item2=$("#mark").val();
            var item3=item1 * item2;
            var item4=item3 + item2;
            $("#markup").change(function(){
                  $("#mark").val(item3);
                  $("$marknet").val(item4);
            });
      });
</script>
0
Hey guys,
I have a long term project I am going to work on. I don't know when I will get there but I need to build an Excel like interface as a web application.

So I'm guessing this will need a lot of JavaScript. So I know basic JavaScript, some jQuery. I have never focused on and learned JavaScript. My plan is to start there.

Udemy is trying to get me to take a React course, I'm tempted to take it just to have something hip on my resume.

What other JavaScript frameworks should I learn?

This is long term, was hoping some people could guide me with this confusing new world of hip JavaScript frameworks. Don't know how to sift through the madness
0
Dear all

I have a script written by thirdies which would need a little upgrade. Using this script I need give to the user the option to Cancel
and to OK.

At the present time the button "OK" just advice the user that limit of characters was exceed, but I need to have 2 options: CANCEL (break) and OK (go ahead)


<script language="JavaScript">
function maxlength(element, maxvalue)
     {
     var q = eval("document.url."+element+".value.length");
     var r = q - maxvalue;
     var msg = "Sorry, you have input "+q+" characters into the "+
       "text area box you just completed. It can return no more than "+
       maxvalue+" characters to be processed. If you exceed the application "+
       "character limit, your text will be cut off at least "+r+" characters";
     if (q > maxvalue) alert(msg);
	 
     }
  
</script>

Open in new window



Thanks in advance

BOB
0
We are working with Dynamics 365 CRM (on-premise) and using a custom front-end developed with ADX.  

My issue is that ADX allows a CRM quote or order to be shared with the same user more than once.  When this is done, we receive an error message: "Cannot insert duplicate key."  (It is my understanding that this is the default Dynamics error).

What I want to do is replace this with a more user-friendly message like: "This order has been already shared with that sales person".

I am looking for the best approach to transform the default error message to the user-friendly message.

Thank you
0
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
I have this json output.
var jsonstr = "{\"formattedResults\":{\"ruleResults\":{\"MinimizeRenderBlockingResources\":{\"localizedRuleName\":\"Eliminate render-blocking JavaScript and CSS in above-the-fold content\",\"ruleImpact\":12.0,\"groups\":[\"SPEED\"],\"summary\":{\"format\":\"Your page has {{NUM_SCRIPTS}} blocking script resources and {{NUM_CSS}} blocking CSS resources. This causes a delay in rendering your page.\",\"args\":[{\"type\":\"INT_LITERAL\",\"key\":\"NUM_SCRIPTS\",\"value\":\"1\"},{\"type\":\"INT_LITERAL\",\"key\":\"NUM_CSS\",\"value\":\"3\"}]},\"urlBlocks\":[{\"header\":{\"format\":\"None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.\"}},{\"header\":{\"format\":\"{{BEGIN_LINK}}Remove render-blocking JavaScript{{END_LINK}}:\",\"args\":[{\"type\":\"HYPERLINK\",\"key\":\"LINK\",\"value\":\"https://developers.google.com/speed/docs/insights/BlockingJS\"}]},\"urls\":[{\"result\":{\"format\":\"{{URL}}\",\"args\":[{\"type\":\"URL\",\"key\":\"URL\",\"value\":\"value 1 output\"}]}}]},{\"header\":{\"format\":\"{{BEGIN_LINK}}Optimize CSS Delivery{{END_LINK}} of the 

Open in new window

0
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
I already have onkeydown for one function called dateformat

My goal is if someone enter date format like 01/01/1972, it will call another function called 'CheckAge' and I want to show the value inside of the <div id="getage"></div>

How can i do that?


 function DateFormat(txt, keyCode) {
        if (keyCode == 16)
            isShift = true;
        //Validate that its Numeric
        if (((keyCode >= 48 && keyCode <= 57) || keyCode == 8 ||
             keyCode <= 37 || keyCode <= 39 ||
             (keyCode >= 96 && keyCode <= 105)) && isShift == false) {
            if ((txt.value.length == 2 || txt.value.length == 5) && keyCode != 8) {
                txt.value += seperator;
            }
            return true;
        }
        else {
            return false;
        }
    }

 function CheckAge(dateString)
    {
        if (dateString != '') {
            var today = new Date();
            var birthDate = new Date(dateString);
            var age = today.getFullYear() - birthDate.getFullYear();
            var m = today.getMonth() - birthDate.getMonth();
            if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
                age--;
            }
            alert(age);
        }
        else
        {
            alert("No Age");
        }
        return age;
        
    }

<div id=GetAge></div>
 <div class="ui-input">
											<input type="date" required tabindex="3" maxlength="10" name="dob" id="dob" onkeydown="return 

Open in new window

0
Hi,

Problem : Timer not working on the dialog properly on the parent page default.aspx. Countdown timer changing time 129 98 78 90 120 67 89 etc like that...

problem2. clicking on any button in details frame will reset session again. Dialog will again disappear 2minutes before timeout and it should show 120 119 118 seconds left....

How to achieve that. Please change my code...

Code

MasterPage.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Masterpage.master.cs" Inherits="Masterpage" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp"%>
<%@ Register Src="~/SessionTimeout.ascx" TagPrefix="uc1" TagName="SessionTimeout" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <asp:ContentPlaceHolder id="head" runat="server">
   </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
  
       <div id="mainContent" >
        <asp:ContentPlaceHolder id="MainContent" runat="server"   >      
        </asp:ContentPlaceHolder>
    </div>
     <uc1:SessionTimeout id="SessionTimeout" runat="server"></uc1:SessionTimeout>
     
    </form>
</body>
</html>
 
SessionTimeout.ascx
 
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SessionTimeout.ascx.cs" Inherits="SessionTimeout" %>
<%@ Register Assembly="AjaxControlToolkit" 

Open in new window

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
I am struggling to complete a formulation for calculating the expiration of data entered which depending on which database table they are in depends on their expectoration time, either 24hrs, 7days, 14days or 21 days.
If there isn't any withing that particular table then it will default to 14.
This is my so far attempt, but have gaps i know and it is so frustrating that I cannot get my head around it....If anyone can shed some light it would be gratefully appreciated.
@example = INT(Table.example/2) MOD 2 <> 0

Open in new window

If {@example} then 1
Else
(

If IsNull{table.NAME} then
14
Else if {table.NAME}= help then
7
Else if {table.NAME} = more help then
21
Else
14
) 

Open in new window

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'd like to have three small pictures on the left and one larger picture to the right of them that changes when the mouse passes over one of the smaller ones.  I'm using this, but its not changing images for me.  Can you see what's wrong? or if its simpler just suggest new code please for Wordpress, Thank You

I tried:
changeImage('img src="https://www.mysite/picture2.jpg')"/> and
changeImage('src="https://www.mysite/picture2.jpg')"/> to see if that would help, it didn't.

<table>
<tr>
<td style="border-width: 3px;" width="5%">
<script type="text/javascript" language="javascript">
                function changeImage(img){
                   document.getElementById('bigImage').src=img;
                }
            </script>
            <div>
                <p><img src="https://www.mysite/picture1.jpg" alt="" width="60" onmouseover="changeImage('img src="https://www.mysite/picture1.jpg')"/></p>
                <p>
<img src="https://www.mysite/picture2.jpg" alt="" width="60" class="size-medium wp-image-2289" onmouseover="changeImage('img src="https://www.mysite/picture2.jpg')"/>
                <p>
<img src="https://www.mysite/picture3.jpg" alt="" width="60" onmouseover="changeImage('img src="https://www.mysite/picture3.jpg')"/>
                <p>&nbsp;</p>
                </br>
            </div>
</td>
<td style="border-width: 3px;" width="25%">
<img src="https://www.mysite/StartingLargePicture.jpg" alt="" id="bigImage" />
</td>
</tr>
</table>
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
What is the best way to test for the existence of an object w/JavaScript ?

We are using Mirth msg engine to move message, Mirth uses Rhino JavaScript to evaluate scripts and return values.
but we don't know the best way to evaluate the existence of an object.

Thanks


var myObj;

if (myObj) { // code }

if (myObj == 'undefined') { // code }

if (myObj.length() > 0 )  { // code }

Open in new window

0
I have a web page with vb.net code behind. The page contains several combo boxes, and goes through some validation rules after user clicks the 'submit' button. If a validation error is found, a hidden <div> is displayed on the web page with the errors. The page scrolls up to the validation <div> using some javascript; see below which is executed from the code behind. For some reason, the javascript is causing the combo boxes and text input fields to be frozen. If the page is refreshed, the user can then modify or update the input controls. Anyone have an idea what is going on?

Javascript:

        Dim script As String = "document.getElementById('ValidationResults').scrollIntoView(true);"
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, True)
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

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.