Skip to content

ErcanOPAK.com

  • ASP.Net WebForms
  • ASP.Net MVC
  • C#
  • SQL
  • MySQL
  • PHP
  • Devexpress
  • Reportviewer
  • About

Category: JavaScript

Development / JavaScript

How to format date in Javascript

- 09.09.24 - ErcanOPAK comment on How to format date in Javascript

function formatDate(date) { var d = new Date(date), month = ” + (d.getMonth() + 1), day = ” + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = ‘0’ + month; if (day.length < 2) day = ‘0’ + day; return [day, month, year].join(‘.’); } OUTPUT: 19.05.2024 NOTE: If you make the return like […]

Read More
ASP.Net MVC / ASP.Net WebForms / Bootstrap / JavaScript

How to change star rating color on mouseover/out, mouseenter/leave with Javascript

- 20.06.23 - ErcanOPAK comment on How to change star rating color on mouseover/out, mouseenter/leave with Javascript

function onMouseEnter(index){ var star = document.getElementsByClassName(“starClass”); var j; for(j = 0; j < fa.length; j++){ if(j < index){ star[j].style.color = “orange”; } else{ star[j].style.color = “#ccc”; } } } function onMouseOut(){ var star = document.getElementsByClassName(“starClass”); var k; for(k = 0; k < fa.length; k++){ star[k].style.color = “#ccc”; } }

Read More
ASP.Net MVC / ASP.Net WebForms / JavaScript

How to disable ASP.Net button after click to prevent double clicking

- 13.01.23 | 20.03.23 - ErcanOPAK comment on How to disable ASP.Net button after click to prevent double clicking

Let’s say you have 2 buttons on your web page. <form id=”form1″ runat=”server”> <asp:Button ID=”Button1″ runat=”server” Text=”Button1″ OnClick=”Button1_Clicked” /> <asp:Button ID=”Button2″ runat=”server” Text=”Button2″ /> </form> Scenario 1: Disabling the specific button <script type=”text/javascript”> function DisableButton() { document.getElementById(“<%=Button1.ClientID %>”).disabled = true; } window.onbeforeunload = DisableButton; </script> The DisableButton JavaScript function is used for disabling specific Button when Clicked. […]

Read More
ASP.Net MVC / ASP.Net WebForms / HTML / JavaScript

How to use client-side function on checkbox or any asp.net component

- 10.11.22 - ErcanOPAK comment on How to use client-side function on checkbox or any asp.net component

Here is the Asp part: <label for=”chkCondition”> <asp:CheckBox ID=”chkCondition” Text=”Should i show the div?” runat=”server” onclick=”ShowHideDiv(this)” /> </label> <hr /> <div id=”divToShowOrHide” style=”display: none”> this div will be shown regarding the checkbox checked status. <asp:TextBox ID=”myTextBox” runat=”server” /> </div> And here is the Javascript part: <script type=”text/javascript”> function ShowHideDiv(chkCondition) { var divToShowOrHide = document.getElementById(“divToShowOrHide”); divToShowOrHide.style.display […]

Read More
ASP.Net MVC / JavaScript

How to remove searching, filtering, ordering and info from Asp.NET MVC Datatable

- 15.09.22 - ErcanOPAK comment on How to remove searching, filtering, ordering and info from Asp.NET MVC Datatable

var table = $(“#datatable”).DataTable({ “paging”: false, “ordering”: false, “searching”: false, “info”: false });  

Read More
ASP.Net MVC / ASP.Net WebForms / JavaScript

How to get session value in Javascript

- 16.04.22 - ErcanOPAK comment on How to get session value in Javascript

<script> let mySession = ‘<%= Session[“SessionName”].ToString() %>’; //use your session … console.log(mySession); alert(mySession); </script>  

Read More
ASP.Net MVC / ASP.Net WebForms / HTML / JavaScript

Search text through Divs in Javascript

- 29.12.21 - ErcanOPAK comment on Search text through Divs in Javascript

<table align=”center” width=”20%”> <tr> <td style=”padding-right: 10px”> <input type=”text” id=”Search” onkeyup=”myFunction()” placeholder=”Please enter a search term..” title=”Type in a name”> </td> </tr> </table> <br> <div class=”target”> This is my DIV element. </div> <div class=”target”> This is another Div element. </div> <div class=”target”> Can you find me? </div> <script> function myFunction() { var input = document.getElementById(“Search”); […]

Read More
JavaScript

How replace characters with asterisks (*) except first characters

- 31.10.21 - ErcanOPAK comment on How replace characters with asterisks (*) except first characters

const theName = “Vincent van Gogh”; function hideWord(word) { if (word.length < 2) return word; return word.substring(0, 1) + ‘*’.repeat(word.length-1); } console.log(theName.split(” “).map(hideWord).join(” “)); OUTPUT: V****** v** G*** You could also wrap the whole lot in a function if you wanted to be able to call it from multiple places and avoid redefining it. function […]

Read More
JavaScript

Smart way to truncate long strings in Javascript

- 28.10.21 - ErcanOPAK comment on Smart way to truncate long strings in Javascript

Let’s say we want to truncate long strings (length > 250): short = long.replace(/(.{250})..+/, “$1&hellip;”); or short = long.replace(/(.{250})..+/, “$1…”);  

Read More
ASP.Net MVC / JavaScript

Populating Javascript array with Model in ASP.Net MVC Razor

- 23.10.21 - ErcanOPAK comment on Populating Javascript array with Model in ASP.Net MVC Razor

We just need to loop through the razor collection to populate the Javascript array as below: @foreach (var item in Model) { @:$(function () { @:$(“#map”).googleMap(); @:$(“#map”).addMarker({ @:coords:[@item.Latitude], @:title: `@item.City, @item.District`, @:text: `@item.Address` @:}); @:}); }  

Read More
ASP.Net MVC / C# / JavaScript

Pass model from Razor view to JavaScript

- 23.10.21 - ErcanOPAK comment on Pass model from Razor view to JavaScript

Let’s say you send a model called “MyModel” from controller to view. In Controller: … var result = new MyModel() { Id = 1, Name = “Ercan”, FavoriteTeam = “Galatasaray”, FavoriteGame = “Half Life Series” } return View(result); … and now we will send this model which comes with result to Javascript via setName function: […]

Read More
JavaScript

Add and Remove classes from element in Javascript

- 23.10.21 - ErcanOPAK comment on Add and Remove classes from element in Javascript

classList is pretty smart and the most modern system of manipulating CSS class names in elements via JavaScript. Adding class name: const element = document.getElementById(‘txtMyText’); element.classList.add(‘myClass’); Removing class name: const element = document.getElementById(‘txtMyText’); element.classList.remove(‘myClass’); Removing multiple class names: const element = document.getElementById(‘txtMyText’); element.classList.remove(‘myClass1’, ‘myClass2’) Thanks to clubmate.fi

Read More
JavaScript

Split and Join in Javascript

- 09.10.21 - ErcanOPAK comment on Split and Join in Javascript

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array.  The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call. Syntax split() split(separator) split(separator, limit) Return value An Array of strings, split at each point where the separator occurs […]

Read More
ASP.Net MVC / ASP.Net WebForms / JavaScript

Getting Session value in Javascript & Asp.Net

- 29.09.21 - ErcanOPAK comment on Getting Session value in Javascript & Asp.Net

<script> var mySessionValue = ‘<%= Session[“SessionName”].ToString() %>’; alert(mySessionValue); </script>  

Read More
JavaScript

Slice() method in Javascript

- 29.09.21 - ErcanOPAK comment on Slice() method in Javascript

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified. Syntax: slice() slice(start) slice(start, end) Parameters start Optional Zero-based index at which to start extraction. A negative index can be used, indicating […]

Read More
JavaScript

Splice() method in Javascript

- 28.09.21 - ErcanOPAK comment on Splice() method in Javascript

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To access part of an array without modifying it, you should use the slice() method. Syntax: splice(start) splice(start, deleteCount) splice(start, deleteCount, item1) splice(start, deleteCount, item1, item2, itemN) Parameters start The index at which to […]

Read More
JavaScript

Pop, Push, Shift and Unshift Array Methods in JavaScript

- 29.08.21 - ErcanOPAK comment on Pop, Push, Shift and Unshift Array Methods in JavaScript

pop(): Remove an item from the end of an array (returns the removed item) push(parameterToAdd): Add items to the end of an array (returns the new array length) shift(): Remove an item from the beginning of an array (returns the removed item) unshift(parameterToAdd): Add items to the beginning of an array (returns the new array […]

Read More
JavaScript

How to use Template literals (Template strings) in Javascript

- 29.08.21 | 29.08.21 - ErcanOPAK comment on How to use Template literals (Template strings) in Javascript

Template literals are enclosed by the backtick (` `) character instead of double or single quotes. Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}). The expressions in the placeholders and the text between the backticks (` `) get passed to a function. let myUnOrderedList = [‘Record1’, ‘Record2’, […]

Read More
Page 1 of 2
1 2 Next »

Posts navigation

Older posts
October 2024
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (848)
  • Get the First and Last Word from a String or Sentence in SQL (756)
  • How to select distinct rows in a datatable in C# (704)
  • How to add default value for Entity Framework migrations for DateTime and Bool (584)
  • Add Constraint to SQL Table to ensure email contains @ (521)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (481)
  • How to make theater mode the default for Youtube (467)
  • Average of all values in a column that are not zero in SQL (453)
  • Find numbers with more than two decimal places in SQL (383)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (371)

Recent Posts

  • How to Reset Taskbar in Windows 11
  • Essential Steps to Take After Windows 11 Updates
  • How to list all tables referencing a table by Foreign Key in MS SQL
  • How to format date in Javascript
  • How to generate a random number for each row in T-SQL
  • How to solve ‘Microsoft.TeamFoundation.Git.Contracts.GitCheckoutConflictException’ problem
  • Why nautical mile equals 1852 mt
  • How to Find Day Name From Date in SQL Server
  • How to make pagination in MS SQL Server
  • How to update Identity Column in SQL Server

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (848)
  • Get the First and Last Word from a String or Sentence in SQL (756)
  • How to select distinct rows in a datatable in C# (704)
  • How to add default value for Entity Framework migrations for DateTime and Bool (584)
  • Add Constraint to SQL Table to ensure email contains @ (521)

Recent Posts

  • How to Reset Taskbar in Windows 11
  • Essential Steps to Take After Windows 11 Updates
  • How to list all tables referencing a table by Foreign Key in MS SQL
  • How to format date in Javascript
  • How to generate a random number for each row in T-SQL

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter

© 2024 ErcanOPAK.com

Proudly powered by WordPress | Theme: Xblog Plus by wpthemespace.com