Just trying to make a random password generator and I'm not getting any output in my alert I'm using to test. Not getting any errors so I'm not sure what my mistake is.
"use strict";
var $ = function(id) { return document.getElementById(id); };
var getRandomNumber = function() {
var num = parseInt$("num").value = "";
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < num.length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
alert(text).toString());
};
var clearFields = function() {
$("num").value = "";
$("password").value = "";
$("num").focus();
};
window.onload = function() {
$("generate").onclick = getRandomNumber;
$("clear").onclick = clearFields;
$("num").focus();
};
You do have an error.
There is an extra ) in this statement alert(text).toString());.
Related
I want my array to be updated as soon as I run the replace function. What actually happens is that all the elements of my array get deleted here is the code:
var Person = [];
var editPersonId = 0;
var Details = [];
function AddPerson() {
this.Details[0] = document.getElementById("fname").value;
this.Details[1] = document.getElementById("lname").value;
this.Details[2] = document.getElementById("age").value;
this.Details[3] = document.getElementById("mobil").value;
this.Details[4] = document.getElementById("adress").value;
Person.push(this.Details);
}
function Clear(){
document.getElementById("fname").value = "";
document.getElementById("lname").value = "";
document.getElementById("age").value ="";
document.getElementById("mobil").value = "";
document.getElementById("adress").value = "";
}
function ShowContacts(){
var testIt= document.getElementById("search").value;
var i=0, k=0, indx=[], msg;
for ( i=0; i < Person.length; i++)
{
for ( k=0; k<=4; k++)
{
if (Person[i][k] === testIt)
{
document.getElementById("newFname").value = Person[i][0];
document.getElementById("newLname").value = Person[i][1];
document.getElementById("newAge").value = Person[i][2];
document.getElementById("newMobil").value = Person[i][3];
document.getElementById("newAdress").value = Person[i][4];
console.log(1);
editPersonId = i;
break;
}
}
}
}
function Replace(){
Person[editPersonId][0] = document.getElementById("newFname").value;
Person[editPersonId][1] = document.getElementById("newLname").value;
Person[editPersonId][2] = document.getElementById("newAge").value;
Person[editPersonId][3] = document.getElementById("newMobil").value;
Person[editPersonId][4] = document.getElementById("newAdress").value;
}
function Run(){
this.AddPerson();
this.Clear();
}
You override the contents of your Person insde of replace().
Person[editPersonId][0] = ...
While editPersonId is 0, means that the item you inserted in AddPerson will be overriden. And before replace(), you run clear(), which empties your inputs. So the elements don't get 'deleted', you replace them with an empty string.
You might wanna look into this article
I'm using crypto-js inside reactjs and everything works fine on localhost.
but on server with chrome I got this error message:
TypeError: Cannot read property 'random' of undefined
on firefox:
TypeError: "r is undefined"
my code:
import CryptoJS from 'crypto-js';
console.log('text',text); //printed on console as well
var p = randomString(10)
console.log('p',p) //printed on console as well
var c = CryptoJS.AES.encrypt(text,p).toString(); // error line
console.log('crypted',c+p)//not printed !
my function:
function setWindow(text){
console.log('text',text);
var p = randomString(10)
console.log('p',p)
var c = CryptoJS.AES.encrypt(text,p).toString();
console.log('crypted',c+p)
return c+p;
}
"crypto-js": "^3.1.9-1",
I don't know where is my problem! I removed node_modules, but I got the same error.
my site:
http://posweb.ccg24.com/signin
updated
function randomString(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
You can generate random without using Math.random
var _ = require('lodash');
var CryptoJS = require("crypto-js");
var p;
function randomString(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var text= _.sampleSize(possible , length).join('');
return text;
}
function setWindow(text){
console.log('text',text);
p = randomString(10)
console.log('p',p)
var c = CryptoJS.AES.encrypt(text,p).toString();
console.log('crypted',c+p)
return c+p;
}
var ciphertext=setWindow("plain text");
var bytes = CryptoJS.AES.decrypt(ciphertext.toString(), p);
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log("decrypte",plaintext);
function randomString(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function setWindow(text){
console.log('text',text);
var p = randomString(10)
console.log('p',p)
var c =CryptoJS.AES.encrypt(text,p);
console.log('crypted',c+p)
return c+p;
}
var text="Plain Text";
setWindow(text);
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
The code here:https://repl.it/#ibrahimth/LastSatisfiedBrain
You can try import * as CryptoJS from 'crypto-js';
I'm getting HTML from a forum url, and parsing the post count of the user from their profile page. I don't know how to write the parsed number into the Google spreadsheet.
It should go account by account in column B till last row and update the column A with count.
The script doesn't give me any errors, but it doesn't set the retrieved value into the spreadsheet.
function msg(message){
Browser.msgBox(message);
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu("Update")
.addItem('Update Table', 'updatePosts')
.addToUi();
}
function getPostCount(profileUrl){
var html = UrlFetchApp.fetch(profileUrl).getContentText();
var sliced = html.slice(0,html.search('Posts Per Day'));
sliced = sliced.slice(sliced.search('<dt>Total Posts</dt>'),sliced.length);
postCount = sliced.slice(sliced.search("<dd> ")+"<dd> ".length,sliced.search("</dd>"));
return postCount;
}
function updatePosts(){
if(arguments[0]===false){
showAlert = false;
} else {
showAlert=true;
}
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var accountSheet = spreadSheet.getSheetByName("account-stats");
var statsLastCol = statsSheet.getLastColumn();
var accountCount = accountSheet.getLastRow();
var newValue = 0;
var oldValue = 0;
var totalNewPosts = 0;
for (var i=2; i<=accountCount; i++){
newValue = parseInt(getPostCount(accountSheet.getRange(i, 9).getValue()));
oldValue = parseInt(accountSheet.getRange(i, 7).getValue());
totalNewPosts = totalNewPosts + newValue - oldValue;
accountSheet.getRange(i, 7).setValue(newValue);
statsSheet.getRange(i,statsLastCol).setValue(newValue-todaysValue);
}
if(showAlert==false){
return 0;
}
msg(totalNewPosts+" new post found!");
}
function valinar(needle, haystack){
haystack = haystack[0];
for (var i in haystack){
if(haystack[i]==needle){
return true;
}
}
return false;
}
The is the first time I'm doing something like this and working from an example from other site.
I have one more question. In function getPostCount I send the function profileurl. Where do I declare that ?
Here is how you get the URL out of the spreadsheet:
function getPostCount(profileUrl){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var thisSheet = ss.getSheetByName("List1");
var getNumberOfRows = thisSheet.getLastRow();
var urlProfile = "";
var sliced = "";
var A_Column = "";
var arrayIndex = 0;
var rngA2Bx = thisSheet.getRange(2, 2, getNumberOfRows, 1).getValues();
for (var i = 2; i < getNumberOfRows + 1; i++) { //Start getting urls from row 2
//Logger.log('count i: ' + i);
arrayIndex = i-2;
urlProfile = rngA2Bx[arrayIndex][0];
//Logger.log('urlProfile: ' + urlProfile);
var html = UrlFetchApp.fetch(urlProfile).getContentText();
sliced = html.slice(0,html.search('Posts Per Day'));
var postCount = sliced.slice(sliced.search("<dd> ")+"<dd> ".length,sliced.search("</dd>"));
sliced = sliced.slice(sliced.search('<dt>Total Posts</dt>'),sliced.length);
postCount = sliced.slice(sliced.search("<dd> ")+"<dd> ".length,sliced.search("</dd>"));
Logger.log('postCount: ' + postCount);
A_Column = thisSheet.getRange(i, 1);
A_Column.setValue(postCount);
};
}
You're missing var in front of one of your variables:
postCount = sliced.slice(sliced.search("<dd> ")+"<dd> ".length,sliced.search("</dd>"));
That won't work. Need to put var in front. var postCount = ....
In this function:
function updatePosts(){
if(arguments[0]===false){
showAlert = false;
} else {
showAlert=true;
}
There is no array named arguments anywhere in your code. Where is arguments defined and how is it getting any values put into it?
I'm want to shorten this function with array
document.mySchedule.breakfast.onchange = function() {
var id = document.mySchedule.breakfast.selectedIndex;
var val = document.mySchedule.breakfast[id].value;
strUser[0]=val;
}
document.mySchedule.lunch.onchange = function() {
var id = document.mySchedule.lunch.selectedIndex;
var val = document.mySchedule.lunch[id].value;
strUser[1]=val;
}
document.mySchedule.dinner.onchange = function() {
var id = document.mySchedule.dinner.selectedIndex;
var val = document.mySchedule.dinner[id].value;
strUser[2]=val;
}
I'm try this way but it didn't seem to be work.
var selectData = ["breakfast","lunch","dinner"]
for(i = 0; i < selectData.lenght; i++) {
document.mySchedule.selectData[i].onchange = function() {
var id = document.mySchedule.selectData[i].selectedIndex;
var val = document.mySchedule.selectData[i][id].value;
strUser[i]=val;
}
}
by the way this use to control selector.
Hope someone can help. thank you
Use:
var selectData = ["breakfast","lunch","dinner"]
for(i = 0; i < selectData.lenght; i++) {
var e = document.getElementById(selectData[i]);
e.onchange = function(){
strUser[i] = e.value;
};
}
I'm trying to build a sophisticated automatic form filler. I wrote the code below, but when I'm trying to run it in FireBug, it keeps saying syntax error.
In this code I am attempting to create a pop up form in the page I am filling, create usernames as demands (function a()). In function Nickname(), I'm getting the users I created in function a(), save it in array, pick a username randomly, fill it out in the appropriate place, and check if it's okay or not. Function pass and checked is filling the rest of the form.
var f = document.createElement("form");
var i = document.createElement("input");
i.type = "text";
i.name = "username";
i.id = "username";
var ien = document.createElement("input");
ien.type = "number";
ien.name = "quantitye";
ien.id = "quantity";
var b = document.createElement("button");
b.onclick = "a()";
var bu = document.createElement("button");
bu.onclick = "bu()";
f.appendChild(i);
f.appendChild(ien);
f.appendChild(b);
f.appendChild(bu);
document.getElementsByTagName('body')[0].appendChild(f);
function a() {
var text = document.getElementById("username").value ;
var i;
var j ;
j = document.getElementById("quantity").value;
var text1 = "";
for(i = 1; i < j ; i++) {
text1+= text + i + " " ;
}
document.write(text1);
}
function Nickname() {
var array =[];
var Guser;
Guser = a();
array = Guser.split(',');
var length = array.length;
var randome = array[math.floor(math.random() * array.length)];
var index = array.indexOf(randome);
document.getElementById("nick").value = randome;
var r = confirm("Is It Okay To Continue ?");
if ( r == true ) {
if(index>-1 && length > -1) {
array.splice(index,1);
}
else if( r != true ) {
randome = array[math.floor(math.random() * array.length)];
document.getElementById("nick").value = randome;
var s = confirm("Is It Okay To Continue ?");
while ( s != true ) {
randome = array[math.floor(math.random() * array.length)];
document.getElementById("nick").value = randome;
}
}
}
}
function pass() {
var password = "123456789m";
document.getElementById("password").value = password;
document.getElementById("pass_conf").value = password;
}
function checked() {
var checked = true ;
document.getElementById(agd).checked = true ;
}
This declaration doesn't look correct:
function all() {
function Nickname() {
Did you really intend to declare Nickname() inside all()?