JavaScriptSource https://javascriptsource.com Search 5,000+ Free JavaScript Snippets Fri, 27 Jan 2023 16:45:23 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://javascriptsource.com/wp-content/uploads/2021/07/cropped-favicon-32x32.png JavaScriptSource https://javascriptsource.com 32 32 How To Generate A Random String In JavaScript https://javascriptsource.com/how-to-generate-a-random-string-in-javascript/ Mon, 17 Apr 2023 08:38:00 +0000 https://javascriptsource.com/?p=1462 Generating a random string in JavaScript can be useful for a variety of tasks, such as generating unique identifiers or password reset tokens. There are a few different ways to generate a random string in JavaScript, but one of the simplest is to use the built-in Math.random() function.

Here is an example of how to use Math.random() to generate a random string of a specified length:

function generateRandomString(length) {
  let result = '';
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const charactersLength = characters.length;
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  return result;
}
console.log(generateRandomString(5)); // example output: "g5X8y"

In this example, the generateRandomString function takes a single argument, length, which specifies the length of the random string to generate. The function then declares a variable result which is initially set to an empty string. Next, it declares a string characters containing all the characters that can be used in the random string.

The function then uses a for loop to iterate length number of times. In each iteration, it uses Math.random() to generate a random number between 0 and 1, and then multiplies that number by the length of the characters string. This results in a random index between 0 and the length of the characters string. The charAt() method is then used to retrieve the character at that index in the characters string, and the result is added to the result string.

Finally, the result string is returned.

You can also use the crypto library to generate a random string. This is particularly useful for cryptographic purposes.

function generateRandomString(length) {
  let result = '';
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const charactersLength = characters.length;
  const crypto = window.crypto || window.msCrypto;
  const array = new Uint8Array(length);
  crypto.getRandomValues(array);
  array.forEach(x => {
    result += characters[x % charactersLength];
  });
  return result;
}
console.log(generateRandomString(5));

In this approach, we use the crypto.getRandomValues() method to generate a random number of bytes, then use the modulo operator % on the value of each byte and the length of characters string to get the corresponding character to concatenate it to the result string.

In both examples, you can change the characters string to suit your needs, for example you can remove characters that you don’t want to include in the string or add more characters to the set.

]]>
How To Generate a GUID in JavaScript https://javascriptsource.com/how-to-generate-a-guid-in-javascript/ Fri, 10 Mar 2023 09:44:00 +0000 https://javascriptsource.com/?p=1414 A globally unique identifier (GUID) is a 128-bit value that is used to identify resources, such as records in a database, in a unique and consistent manner across different systems. In JavaScript, there are several libraries and built-in methods that can be used to generate a GUID.

One way to generate a GUID in JavaScript is to use the crypto module, which is built into modern web browsers and Node.js. The crypto.getRandomValues() method generates a cryptographically-secure, random array of values that can be used to create a GUID. Here is an example of how to use the crypto module to generate a GUID:

function generateGUID() {
  const array = new Uint8Array(16);
  crypto.getRandomValues(array);

  array[6] = (array[6] & 0x0f) | 0x40;
  array[8] = (array[8] & 0x3f) | 0x80;

  let guid = '';
  for (let i = 0; i < array.length; i++) {
    let value = array[i].toString(16);
    if (value.length === 1) {
      value = '0' + value;
    }
    guid += value;
    if (i === 3 || i === 5 || i === 7 || i === 9) {
      guid += '-';
    }
  }
  return guid;
}

Another popular library for generating GUIDs in JavaScript is the uuid library. It is a simple, lightweight library that can be used to generate a GUID in a single line of code:

const uuid = require('uuid');

const newGUID = uuid.v4();

or

import { v4 as uuidv4 } from 'uuid';
const newGUID = uuidv4();

Both of these methods will generate a unique GUID that can be used to identify resources in a consistent and unique manner. You can choose which method you prefer or which fits your use case best.

]]>
Range generator https://javascriptsource.com/range-generator/ Fri, 19 Aug 2022 09:35:00 +0000 https://javascriptsource.com/?p=1232 Creates a generator, that generates all values in the given range using the given step. Use a while loop to iterate from start to end, using yield to return each value and then incrementing by step. Omit the third argument, step, to use a default value of 1.

const rangeGenerator = function* (start, end, step = 1) {
  let i = start;
  while (i < end) {
    yield i;
    i += step;
  }
};

// EXAMPLE
for (let i of rangeGenerator(6, 10)) console.log(i);
// Logs 6, 7, 8, 9

Source

https://www.30secondsofcode.org/js/s/range-generator

]]>
Generate a random hexadecimal color code https://javascriptsource.com/generate-a-random-hexadecimal-color-code/ Mon, 04 Apr 2022 10:48:00 +0000 https://javascriptsource.com/?p=1095 Use Math.random() to generate a random 24-bit (6 * 4bits) hexadecimal number. Use bit shifting and then convert it to an hexadecimal string using Number.prototype.toString().

Also check out this random color generator.

const randomHexColorCode = () => {
  let n = (Math.random() * 0xfffff * 1000000).toString(16);
  return '#' + n.slice(0, 6);
};

// EXAMPLE
randomHexColorCode(); // '#e34155'

Source

https://www.30secondsofcode.org/js/s/random-hex-color-code

]]>
DHTML Tooltip Generator 3 https://javascriptsource.com/dhtml-tooltip-generator-3/ Sat, 13 Jan 2018 19:20:00 +0000 https://the-js-source.flywheelsites.com/?p=276 Sometimes the HTML “alt=” isn’t enough to relay the detail you’d like it to. Here is a tooltip generator that will allow you to give your users more interactive tooltips. This script will allow you to create a custom DHTML tooltip box on your site.

<!– STEP ONE: Paste this code into the BODY of your HTML document  –>

<BODY>

<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Spriteworks Developments  –>

<!– Web Site:  http://www.spriteworks.com –>

      <SCRIPT language = “javascript”>

      <!–







      var ie = document.all ? 1 : 0



      var ns = document.layers ? 1 : 0











      if(ie){



      document.write(‘<style type=”text/css”>’)







      document.write(‘.textfield {font-size:10pt; font-family:arial; color:#808080; font-weight:bold;}n’)



      document.write(‘.hexfield {font-size:10pt; font-family:arial; color:#808080; font-weight:bold;}n’)



      document.write(‘.buttons {border-style: solid; background-color: #808080; border-color: #000000; border-width: 1; color: #FFFFFF; font-size: 10pt; font-family: arial; font-weight: bold;}n’)







      document.write(‘</style>’)



      }







      //–> </SCRIPT>

      <CENTER>

	<SCRIPT language=”JavaScript” src=’http://www.guistuff.com/gens/tooltip.js’></SCRIPT>

      </CENTER>



<p><center>

<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>

by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>

</center><p>
]]>
Array Creator 3 https://javascriptsource.com/array-creator-3/ Sat, 13 Jan 2018 18:24:00 +0000 https://the-js-source.flywheelsites.com/?p=260 General

Coding large arrays can be a bit of a repetitive chore. This script will create a generator that will help speed up the process. Easy to use and implement!

Notes

  • Created by: Mr. J
  • Web Site: http://www.huntingground.net/
  • When using the numerical value option enter the array length and an index value.
  • A number is then appended to the index value starting at 000.
  • A second value can also be added after the number by entering in the second textbox, if this is not required leave the box blank.
  • If the numerical value option is not used each individual array index value is typed in the text field, you can then either click the “Manual Enter” button or press the “Return” key to confirm your index value.

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: arrayCreator.js

/* This script and many more are available free online at
The JavaScript Source!! http://javascriptsource.com
Created by: Mr. J | http://www.huntingground.net/ */

function init(){
  array_name=document.f1.t1.value //name of array
  val2=document.f1.t3a.value
  ext=document.f1.t4.value
  for(r=0;r<document.f1.r1.length check="" which="" r1="" radio="" is="" selected="selected" if="" option="document.f1.r1[r].value" value="" document.getelementbyid="" new="" array="" opening="" type="" else=""></document.f1.r1.length>” // opening array type 2 & 3
  }

  if(document.f1.r2[0].checked==true){ // if indexed values
    make_array1()
  }

  if(document.f1.r2[1].checked==true){ // if non index values
    make_array2()
  }
}

function make_array1(){
  array_length=document.f1.t2.value-1 // length of array
  index_values=document.f1.t3.value // index value

  if(array_length==””||array_length==0){ // make sure a viable number is used
    document.getElementById(“display”).innerHTML=”Please Enter a Number”
    document.f1.b2.disabled=true
    return
  } else {
    if(!ns){document.f1.cpy.disabled=false}
  }

  for(num=0;num<array_length j="num" if="">9&&num0){
      i=num+val2+ext}
      else{i=num+val2}

  if(option==0){ // insert inner indexes for type 1
    document.getElementById(“display”).innerHTML+=”””+index_values+i+””, ”
  } else {
    if(option==1){ // insert inner indexes for type 2
      document.getElementById(“display”).innerHTML+=array_name+”[“+j+”]=”
      document.getElementById(“display”).innerHTML+=”””+index_values+i+””<br />”
    } else { // insert inner indexes for type 3
      document.getElementById(“display”).innerHTML+=array_name+”[“+array_name+”.length]=””+index_values+i+””<br />”
    }
  }
}

if(num9&&num100){num=num}

if(document.f1.t4.value.length>0){
  i= num+val2+ext}
  else{i=num+val2}

  if(option==0){ // insert last indexes for type 1
    document.getElementById(“display”).innerHTML+=”””+index_values+i+””)”
  } else {
    if(option==1){ // insert last indexes for type 2
      document.getElementById(“display”).innerHTML+=array_name+”[“+(j+1)+”]=”
      document.getElementById(“display”).innerHTML+=”””+index_values+i+””<br />”
    } else { // insert last indexes for type 3
      document.getElementById(“display”).innerHTML+=array_name+”[“+array_name+”.length]=””+index_values+i+””<br />”
    }
  }
}

index_value=new Array()
count= 0
last=0

function make_array2(){
  if(!ns){document.f1.cpy.disabled=false}
  for(r=0;r<document.f1.r1.length check="" which="" r1="" radio="" is="" selected="selected" if="" chkrad="r" prevent="" additional="" index="" when="" only="" changing="" array="" style="" count--="">0){
    index_value[count]=document.f1.t3.value+ext}
  else {
    index_value[count]=document.f1.t3.value
  }

  for(i=0;i<count if="" document.getelementbyid="" else=""></count>”
      } else {
        document.getElementById(“display”).innerHTML+=array_name+”[“+i+”]=””+index_value[i]+””<br />”
      }
    }
  }

  if(option==0){
    document.getElementById(“display”).innerHTML+=”””+index_value[i]+””)”
  } else {
    if(option==2){
      document.getElementById(“display”).innerHTML+=array_name+”[“+array_name+”.length]=””+index_value[i]+””<br />”
    } else {
      document.getElementById(“display”).innerHTML+=array_name+”[“+i+”]=””+index_value[i]+””<br />”
    }
  }
  count++
  document.f1.t3.select()
  last=chkrad
}

function oreset(){
  count=0
  document.f1.t3.value=””
  document.getElementById(“display”).innerHTML=””
  document.f1.t3.select()
}

function chk(){
  if(document.f1.r2[0].checked==true){
    document.f1.t2.disabled=false
    document.getElementById(“sp”).disabled=false
    document.f1.t2.style.backgroundColor=”#FFFFFF”
    document.f1.b1.disabled=false
    document.f1.b2.disabled=true
    document.f1.b3.disabled=true
    document.f1.t3a.disabled=false
    document.f1.t3a.style.backgroundColor=”#FFFFFF”
  } else {
    document.f1.t2.disabled=true
    document.getElementById(“sp”).disabled=true
    document.f1.t2.style.backgroundColor=”#c0c0c0″
    document.f1.b1.disabled=true
    document.f1.b2.disabled=false
    document.f1.b3.disabled=false
    document.f1.t3.select()
    document.f1.t3a.disabled=true
    document.f1.t3a.style.backgroundColor=”#c0c0c0″
  }
}

function Copy(id){
  if(ns){
    alert(“Sorry, Netscape does not recongise this function”)
    document.f1.cpy.disabled=true
    return
  }
  copyit=id
  textRange = document.body.createTextRange();
  textRange.moveToElementText(copyit);
  textRange.execCommand(“Copy”);
  alert(“Copying Complete.nnPlease Paste into your SCRIPT”)
}

ns=document.getElementById&&!document.all

function getKey(e) {
  pressed_key=(!ns)?event.keyCode:e.which
  if( pressed_key==13){
    init()
  }
}
document.onkeypress = getKey;

</document.f1.r1.length></array_length>

CSS

Paste this code into your external CSS file or in the <style> section within the HEAD section of your HTML document.

#display {
  position: relative;
  left: 10px;
  width: 450px;
  border: 1px solid black;
  padding: 10px;
}

Head

Paste this code into the HEAD section of your HTML document.

<script type=”text/javascript” src=”arrayCreator.js”></script>

Body

Paste this code into the BODY section of your HTML document.

<form name="f1" id="f1">

<table border="0"><tr><td>Array Name:</td>
    <td colspan="6">
      <input type="text" name="t1" value="myArray" /></td>
  </tr><tr><td>
      <span id="sp">Indexed Array Length:</span>
    </td>
    <td colspan="6">
      <input type="text" name="t2" value="5" size="3" maxlength="3" /></td>
  </tr><tr><td>Index Value:</td>
    <td colspan="6">
      <input type="text" name="t3" value="image" size="10" /><input type="text" name="t3a" value="_tn" size="10" /> Ext
      <input type="text" name="t4" value=".jpg" size="4" maxlength="4" /></td>
  </tr><tr><td>Index Style:</td>
    <td align="right">1
      <input type="radio" name="r1" value="0" checked="checked" onclick="init()" /></td>
    <td> </td>
    <td align="right">2
      <input type="radio" name="r1" value="1" onclick="init()" /></td>
    <td> </td>
    <td align="right">3
      <input type="radio" name="r1" value="2" onclick="init()" /></td>
    <td width="80"> </td>
  </tr><tr><td>Add Numerical Values:</td>
    <td align="right">Yes
      <input type="radio" name="r2" value="0" checked="checked" onclick="chk()" /></td>
    <td align="center"> </td>
    <td align="right">No
      <input type="radio" name="r2" value="1" onclick="chk()" /></td>
    <td> </td>
    <td colspan="2"> </td>
  </tr><tr align="center"><td>
      <input type="button" name="b1" value="Numerical Enter" onclick="init()" /></td>
    <td colspan="6">
      <input type="button" name="cpy" value="Copy Array" onclick="Copy(display)" disabled="disabled" /><input type="button" name="b2" value="Manual Enter" onclick="init()" disabled="disabled" /><input type="button" name="b3" value="Restart" onclick="oreset()" disabled="disabled" /></td>
  </tr></table></form>

<div id="display"></div>
]]>
Flashing Scrollbar Maker https://javascriptsource.com/flashing-scrollbar-maker/ Sat, 13 Jan 2018 17:56:00 +0000 https://the-js-source.flywheelsites.com/?p=250 This script lets you create your own flashing scroll bars. Simply type in two colors to the prompt and let JavaScript do the rest!

  1. Copy the coding into the HEAD of your HTML document
  2. Add the last code into the BODY of your HTML document
<!– STEP ONE: Paste this code into the HEAD of your HTML document  –>



<HEAD>



<SCRIPT LANGUAGE=”JavaScript”>

<!– Original:  Jamie Allen –>

<!– Web Site:  http://www.jamie.zibykid.com –>

<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>



<script language=”JavaScript”>

//This script may be used, UNEDITED

//www.jamie.zibykid.com

function flashingscrollbars(){

//Colour 1 for scrollbars

pr1 = prompt(‘Choose a first color for your scrollbarsn(USE ONLY SMALL LETTERS! e.g. blue NOT Blue or BLUE)’, ”);

hid1.value=pr1

var done=0

if (hid1.value==”null”) { location.reload(self); done=1; }

if (hid1.value==”crimson”) { gogo(); done=1; }

if (hid1.value==”khaki”) { gogo(); done=1; }

if (hid1.value==”red”) { gogo(); done=1; }

if (hid1.value==”blue”) { gogo(); done=1; }

if (hid1.value==”silver”) { gogo(); done=1; }

if (hid1.value==”teal”) { gogo(); done=1; }

if (hid1.value==”gray”) { gogo(); done=1; }

if (hid1.value==”gold”) { gogo(); done=1; }

if (hid1.value==”#fafafa”) { gogo(); done=1; }

if (hid1.value==”pink”) { gogo(); done=1; }

if (hid1.value==”purple”) { gogo(); done=1; }

if (hid1.value==”violet”) { gogo(); done=1; }

if (hid1.value==”turquoise”) { gogo(); done=1; }

if (hid1.value==”brown”) { gogo(); done=1; }

if (hid1.value==”white”) { gogo(); done=1; }

if (hid1.value==”black”) { gogo(); done=1; }

if (hid1.value==”green”) { gogo(); done=1; }

if (hid1.value==”orange”) { gogo(); done=1; }

if (hid1.value==”maroon”) { gogo(); done=1; }

if (hid1.value==”lime”) { gogo(); done=1; }

if (hid1.value==”cyan”) { gogo(); done=1; }

if (hid1.value==”magenta”) { gogo(); done=1; }

if (done==0) { if(confirm(‘There seems to have been an error on your first colour!nPlease try again!’)) { flashingscrollbars(); } else { location.reload(self); } }

}

//Second check for colours (Color 2)

function gogo(){

pr2 = prompt(‘Choose a second color for your scrollbars’, ”);

hid2.value=pr2

var done=0

if (hid2.value==”null”) { location.reload(self); done=1; }

if (hid2.value==”crimson”) { gogo2(); done=1; }

if (hid2.value==”khaki”) { gogo2(); done=1; }

if (hid2.value==”red”) { gogo2(); done=1; }

if (hid2.value==”blue”) { gogo2(); done=1; }

if (hid2.value==”silver”) { gogo2(); done=1; }

if (hid2.value==”teal”) { gogo2(); done=1; }

if (hid2.value==”gray”) { gogo2(); done=1; }

if (hid2.value==”gold”) { gogo2(); done=1; }

if (hid2.value==”#fafafa”) { gogo2(); done=1; }

if (hid2.value==”pink”) { gogo2(); done=1; }

if (hid2.value==”purple”) { gogo2(); done=1; }

if (hid2.value==”violet”) { gogo2(); done=1; }

if (hid2.value==”turquoise”) { gogo2(); done=1; }

if (hid2.value==”brown”) { gogo2(); done=1; }

if (hid2.value==”white”) { gogo2(); done=1; }

if (hid2.value==”black”) { gogo2(); done=1; }

if (hid2.value==”green”) { gogo2(); done=1; }

if (hid2.value==”orange”) { gogo2(); done=1; }

if (hid2.value==”maroon”) { gogo2(); done=1; }

if (hid2.value==”lime”) { gogo2(); done=1; }

if (hid2.value==”cyan”) { gogo2(); done=1; }

if (hid2.value==”magenta”) { gogo2(); done=1; }

if (done==0) { if(confirm(‘There seems to have been an error on your second colour!nPlease try again!’)) { gogo(); } else { location.reload(self); } }

}

//If everything’s OK, this script will allow you to preview it in your browser.

function gogo2(){

preview.disabled=false

cut_paste_box.value=”n<script language=”JavaScript”>nfunction go1(){ndocument.body.style.scrollbarBaseColor=””+hid1.value+””;nsetTimeout(‘clr2()’, 500)n}nfunction clr2(){ndocument.body.style.scrollbarBaseColor=””+hid2.value+””nsetTimeout(‘go1()’, 500)n}n</script>n<script language=”JavaScript”>ngo1()n</script>”

}

function prev(){

//The actual document.write (preview) script

document.write(‘n<html>n<head>n</head>n<body bgcolor=”#000000″ text=”#FFFF00″ link=”#00FF00″ vlink=”#00FF00″ alink=”#00FFFF”>n<center>n<p align=”center”>You should see the scrollbar flashing (as log as you’ve picked 2 different colors!)</p>n<p>Color 1 = ‘+hid1.value+'</p>n<p>Color 2 = ‘+hid2.value+'</p>n’+cut_paste_box.value+’n<p>Copy and Paste the following code, in your webpage, after the <body> tag.</p>n<textarea rows=”8″ cols=”75″>’+cut_paste_box.value+'</textarea></center>n<p align=”center”><a href=”javascript:history.back(-1);”>Back…</a>n</p>n</body>n</html>’)

}

</script>



</HEAD>
<!– STEP TWO: Copy this code into the BODY of your HTML document  –>



<BODY>



<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Jamie Allen –>

<!– Web Site:  http://www.jamie.zibykid.com –>

<p align=”center”><font size=”6″ face=”tahoma”><strong>Flashing Scrollbar Maker</strong></font></p>

<p align=”center”><font size=”3″ face=”tahoma”><strong>v1.1</strong></font></p>

<p align=”center”> 

  <input type=”button” value=”Create some flashing scrollbars!” name=”go” onClick=”flashingscrollbars()”>

</p>

<div align=”center”>

  <center>

  <table border=”0″ cellpadding=”3″ cellspacing=”0″ width=”93%”>

    <tr>

      <td width=”108%”>

        <p align=”center”> <textarea disabled rows=”1″ cols=”1″ name=”cut_paste_box” style=”background-color: #000000; border-style: solid; border-width: 0″></textarea>

        <p align=”center”> 

            <input disabled type=”button” value=”Preview Scrollbars” name=”preview” onclick=”prev()”>

          </td>

    </tr>

    <tr>

      <td width=”100%” align=”center”>

        <p align=”center”>  <font color=”#00FF00″ face=”Tahoma”>NOTE: Press 

            “Preview” to get the copy & paste code to put onto your 

            webpage </font></td>

    </tr>

  </table>

  </center>

</div>

<p align=”center”><input id=”hid1″ type=”hidden”></p>

<p align=”center”><input id=”hid2″ type=”hidden”></p>

<p align=”center”><input id=”hid3″ type=”hidden”></p>

<script>

cut_paste_box.value=””

cut_paste_box.style.scrollbar3dLightColor=”black”

cut_paste_box.style.scrollbarHighlightColor=”black”

cut_paste_box.style.scrollbarFaceColor=”black”

cut_paste_box.style.scrollbarArrowColor=”black”

cut_paste_box.style.scrollbarShadowColor=”black”

cut_paste_box.style.scrollbarDarkShadowColor=”black”

</script>





<p><center>

<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>

by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>

</center><p>
]]>
Robots Text Generator https://javascriptsource.com/robots-text-generator/ Sat, 13 Jan 2018 16:17:00 +0000 https://the-js-source.flywheelsites.com/?p=218 This generator creates the meta tag for robots. It also includes the code for the Googlebot.

<!– Paste this code into the CSS section of your HTML document  –>

.table1 {
  border: solid .05em;
  padding: .5em;
}
<!– Paste this code into an external JavaScript file named: roboTxt.js  –>

/* This script and many more are available free online at
The JavaScript Source :: http://javascriptsource.com
Created by: Lee Underwood :: http://javascriptsource.com/ */

function createRobotTag() {
  var robotsTag=”<meta name=”robots” content “”;

  if (document.getElementById(“none”).checked) {
    robotsTag += “none”>”;
    document.getElementById(“index”).disabled=true;
    document.getElementById(“follow”).disabled=true;
  } else if (document.getElementById(“none”).checked==false) {
    document.getElementById(“index”).disabled=false;
    document.getElementById(“follow”).disabled=false;
    if (document.getElementById(“index”).checked) {
      robotsTag += “noindex, “;
    } else {
      robotsTag += “index, “;
    }
    if(document.getElementById(“follow”).checked) {
      robotsTag += “nofollow”>”;
    } else {
      robotsTag += “follow”>”;
    }
  }
  document.getElementById(“tag”).value = robotsTag;
}

function googTag() {
  var googleTag=”<meta name=”Googlebot” content=”nofollow”>”;
  if (document.getElementById(“googleBot”).checked) {
    document.getElementById(“tag2”).value = googleTag;
  } else {
    document.getElementById(“tag2”).value = “”;
  }
}

function copyToClipboard() {
  document.getElementById(“tag”).focus();
  document.getElementById(“tag”).select();
  copiedTxt=document.selection.createRange();
  copiedTxt.execCommand(“Copy”);
}

function copyToClipboard2() {
  document.getElementById(“tag2”).focus();
  document.getElementById(“tag2”).select();
  copiedTxt2=document.selection.createRange();
  copiedTxt2.execCommand(“Copy”);
}
<!– Paste this code into the HEAD section of your HTML document.
     You may need to change the path of the file.  –>

<script type=”text/javascript” src=”roboTxt.js”></script>
<!– Paste this code into the BODY section of your HTML document  –>

<table width=”60%” align=”center” class=”table1″>
<tr><td>
<form>
<input type=”checkbox” id=”none” onclick=”createRobotTag()”> <strong>Tell robots to ignore this page</strong>
<br>
<input type=”checkbox” id=”index” onclick=”createRobotTag()”> <strong>Tell robots to not index this page in the search engines</strong>
<br>
<input type=”checkbox” id=”follow” onclick=”createRobotTag()”> <strong>Tell robots to not follow any of the links on this page</strong>
<p>
Insert this meta tag in the <head> section of your Web page:<br>
<input type=”text” size=”50″ id=”tag” readonly><br>
<input type=”button” onClick=”copyToClipboard()” value=”Copy to clipboard”><br><small>[<em>Netscape, Firefox, and Opera users – Press button to select and  [Ctrl]+C to copy</em>]</small>
<br><br><br>
<input type=”checkbox” id=”googleBot” onclick=”googTag()”> <strong>Tell only the Googlebot to ignore this page</strong>
<p>
Insert this meta tag in the <head> section of your Web page:<br>
<input type=”text” size=”50″ id=”tag2″ readonly><br>
<input type=”button” onClick=”copyToClipboard2()” value=”Copy to clipboard”><br><small>[<em>Netscape, Firefox, and Opera users – Press button to select and [Ctrl]+C to copy</em>]</small>
</form>
</td></tr>
</table>
<p><div align=”center”>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>
</div><p>
]]>
Drop Down Menu Generator https://javascriptsource.com/drop-down-menu-generator/ Fri, 12 Jan 2018 22:14:00 +0000 https://the-js-source.flywheelsites.com/?p=183 Simply select the options you would like in your pulldown menu, enter the text and URL for each listing, and click the button to generate the source code. Easy! And, we can even mail the generated code to you!

Load selected page immediately
Use button
Use image button (url=)
Pulldown Menu Entries:
Text Shown Link URL

Cut and paste the code above, or …

… we’ll send the generated code to you!

(just click “Send it!” once!)

]]>
Linear Equation Generator https://javascriptsource.com/linear-equation-generator/ Fri, 12 Jan 2018 20:42:00 +0000 https://the-js-source.flywheelsites.com/?p=147 This Linear Equation generator asks you to find the relationship between X and Y. This is a straight line formula in the form of Y=MX+B where M is the slope and B is the y-intersect.

X 1 2 3 4 5
Y          

Y = X +

 

  1. Copy the coding into the HEAD of your HTML document
  2. Add the onLoad event handler into the BODY tag
  3. Put the last coding into the BODY of your HTML document
<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Benjamin M. Joffe ([email protected]) –>

<!– Web Site:  http://www.rollingtank.com/benjoffe/ –>

<script>

var gradient=0;

var intersect=0;

function domath(){

gradient=0;

intersect=0;

while ((gradient==0 || gradient==1)) gradient=Math.round(Math.random()*60- 30)/2;

while (intersect==0) intersect=Math.round(Math.random()*60- 30)/2;

xone.innerHTML=gradient+intersect;

xtwo.innerHTML=2*gradient+intersect;

xthree.innerHTML=3*gradient+intersect;

xfour.innerHTML=4*gradient+intersect;

xfive.innerHTML=5*gradient+intersect;

}

function checkmath(){

if (gradientanswer.value==gradient & intersectanswer.value==intersect) {correct.innerHTML=”Correct”}

else {correct.innerHTML=”Incorrect”;}

}

function revert(){correct.innerHTML=””}

</script>
<BODY onLoad="domath()">
<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Benjamin M. Joffe ([email protected]) –>

<!– Web Site:  http://www.rollingtank.com/benjoffe/ –>

<table class=main border=”0″ cellpadding=”0″ cellspacing=”0″ width=”400″ height=”350″>

  <tr>

    <td align=”center”>

<p style=font-size:14pt;font-weight:bold;>Maths Quiz Two</p>

<p>This maths question generator asks you to find the relationship between X and

Y. This is a linear  fucntion in the form of Y=MX+B where M is the gradient

and B is the y-intersect.</p>

<p><input type=”button” value=”New Question” onclick=domath() class=”form”></p>

<table border=”1″ cellpadding=”5″ cellspacing=”0″ bgcolor=”#003366″>

  <tr>

    <td>X</td>

    <td align=”center”>1</td>

    <td align=”center”>2</td>

    <td align=”center”>3</td>

    <td align=”center”>4</td>

    <td align=”center”>5</td>

  </tr>

  <tr>

    <td>Y</td>

    <td id=xone> </td>

    <td id=xtwo> </td>

    <td id=xthree> </td>

    <td id=xfour> </td>

    <td id=xfive> </td>

  </tr>

</table>

<p>Y = <input type=”text” size=”4″ maxlength=5 onkeydown=revert() id=gradientanswer class=”form”>

X + <input type=”text” size=”5″ maxlength=5 onkeydown=revert() id=intersectanswer class=”form”>

<input type=”button” onclick=checkmath() value=” OK ” class=”form”></p>

<p id=”correct”> </p>

</td>

  </tr>

</table>



<p><center>

<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>

by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>

</center><p>
]]>