function turn(id, player) {
let value = parseInt($('#' + id).attr('data-value'));
showValue();
id = parseInt(id);
for (let i = 1; i <= value; i++) {
let newId = id + i;
setTimeout(function () {
if (player == 'p1') {
let value = parseInt($('#' + newId).attr('data-value'));
if (newId == 14) {
let mainValue = parseInt($('#main-1').attr('data-value'));
$('#main-1').attr('data-value', mainValue + 1);
// i want to add i++; but nothing happen
} else {
$('#' + newId).attr('data-value', value + 1);
}
} else {
let value = parseInt($('#' + newId).attr('data-value'));
if (newId == 7) {
let mainValue= parseInt($('#main-2').attr('data-value'));
$('#main-2').attr('data-value', mainValue + 1);
//here too
} else {
$('#' + newId).attr('data-value', value + 1);
}
} showValue();
}, i * 500);
}
}
when i console.log the i in that spot, nothing happened.
but when i change i outside setTimeout function, it works.
how can i fix that?
You should use setInterval instead of setTimeout in your case.
function turn(id, player) {
let value = parseInt($("#" + id).attr("data-value"));
showValue();
id = parseInt(id);
let i = 1;
const timer = setInterval(function () {
if (player == "p1") {
let newId = id + i;
let value = parseInt($("#" + newId).attr("data-value"));
if (newId == 14) {
let mainValue = parseInt($("#main-1").attr("data-value"));
$("#main-1").attr("data-value", mainValue + 1);
// i want to add i++; but nothing happen
} else {
$("#" + newId).attr("data-value", value + 1);
}
} else {
let value = parseInt($("#" + newId).attr("data-value"));
if (newId == 7) {
let mainValue = parseInt($("#main-2").attr("data-value"));
$("#main-2").attr("data-value", mainValue + 1);
//here too
} else {
$("#" + newId).attr("data-value", value + 1);
}
}
showValue();
i++;
if (i > value) {
clearInterval(timer);
}
}, 500);
}
function turn(id, player) {
let value = parseInt($('#' + id).attr('data-value'));
showValue();
id = parseInt(id);
let i = 1;
for (i = 1; i <= value; i++) {
let newId = id + i;
setTimeout(function () {
if (player == 'p1') {
let value = parseInt($('#' + newId).attr('data-value'));
if (newId == 14) {
let mainValue = parseInt($('#main-1').attr('data-value'));
$('#main-1').attr('data-value', mainValue + 1);
i++;
} else {
$('#' + newId).attr('data-value', value + 1);
}
} else {
let value = parseInt($('#' + newId).attr('data-value'));
if (newId == 7) {
let mainValue= parseInt($('#main-2').attr('data-value'));
$('#main-2').attr('data-value', mainValue + 1);
i = i + 1
} else {
$('#' + newId).attr('data-value', value + 1);
}
} showValue();
}, i * 500);
}
}
I think this here should work as it worked for me! Have a nice day :)
SOLVED TLDR EDIT: I am stupid and tried to get "message" in the ready event, so yea, look up what the code that you're copy and pasting does lads!
Simply put: I made a discord bot in javascript, checked it with JSHint and then ran it on node.js.
The problem: everytime i ran the bot, i got the "msg is not defined" error
I found already answered questions (Question 1, Question 2) but i looked at the solutions listed in the comments of them and it was already like how the commenters said it should be.
Note: the node.js server is on an android phone, and i already installed discord.js on it.
Source code of my bot:
const Discord = require('discord.js');
const client = new Discord.Client();
var delayed = [];
var funcs = {
clean: function(text) {
var temp = "";
text = text + "";
for (var i = 0; i < text.length; i++) {
if (text.charAt(i) != "_" && text.charAt(i) != "*" && text.charAt(i) != "`" && text.charAt(i) != " ") {
temp = temp + text.charAt(i);
}
}
return temp.toLowerCase();
},
log: function(logthat, cmddude) {
console.log(Date().slice(4, 24) + " | " + logthat + " | " + cmddude + "\n");
},
cook: function(cookthishex) {
cookthishex = cookthishex + '';
var returning = '';
for (var i = 0; i < cookthishex.length; i += 2) {
returning += String.fromCharCode(parseInt(cookthishex.substr(i, 2), 16));
}
return returning;
},
random: function(low, high) {
return Math.round(Math.random() * (high - low)) + low
},
delay: function(userid) {
delayed.push(userid);
setTimeout(function(Argument) {
var temp = delayed[delayed.indexOf(Argument)];
delayed[delayed.indexOf(Argument)] = delayed[delayed.length];
delayed[delayed.length] = temp;
delayed.pop();
}, 1000, userid);
},
split(argtext) {
var splitlist = [], splittext = "";
for (var i = 0; i < argtext.length; i++) {
if (argtext.charAt(i) === " ") {
splitlist.push(splittext);
splittext = "";
} else {
splittext = splittext + argtext.charAt(i);
}
}
if (splittext.charAt(splittext.length - 1) === " ") {
splitlist.push(splittext);
}
return splitlist;
}
};
client.on('ready', () => {
console.log("Logged in as ${client.user.tag}!");
funcs.log("activated");
var reacttocomment = true;
if (client.guilds.get(msg.guild.id).roles.find(x => x.name == "No Bruh") == null) {
client.guilds.get(msg.guild.id).createRole({
name: "No Bruh",
color: "0xf0f0f0",
mentionable: false
}, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
}
});
client.on('message', msg => {
if (delayed && msg.author.id !== "492665478687490048") return;
if (msg.author.bot) return;
if (msg.author.id === "489572485126422529") return;
var msgcont = msg.content.slice(13);
if (reacttocomment === true) {
if (funcs.clean(msg.content) === 'bruh' && msg.member.roles.some(r => r.name === "No Bruh") === true) {
delayed.push(msg.author.id);
funcs.log("bruh", msg.author.id);
msg.channel.reply('bruh');
delay(msg.author.id);
}
if (msg.content.slice(0,10) === 'bruh!invite') {
delayed.push(msg.author.id);
funcs.log("invite", msg.author.id);
msg.channel.reply('(invite doesnt exist right now, this bot is currently being tested.)');
delay(msg.author.id);
}
if (msg.content.slice(0, 8) === 'bruh!help') {
delayed.push(msg.author.id);
funcs.log("help", msg.author.id);
msg.channel.reply('`I am "Bruh Bot" [Prefix: bruh!]`\n' +
'`My mission is to reply with "bruh" when someone writes "bruh".`\n' +
'```command list:\n' +
'help: This.\n' +
'invite: Gives bot invite link.\n' +
'noreact: The bot wont react to you with "bruh" if you say it.```\n' +
'random: Get a random number from A to B.```\n' +
'avatar: Display the URL of your avatar.```\n' +
'doreact: The bot will react to you with "bruh" if you say it.```\n' +
'rate: Rates the action/attribute/object you give it.```\n' +
'ping: Get bot "latency".```\n' +
'**`Have a good day (or night)!`**');
delay(msg.author.id);
}
if (msg.content.slice(0, 11) === 'bruh!noreact') {
delayed.push(msg.author.id);
funcs.log("noreact", msg.author.id);
msg.member.addRole('No Bruh');
msg.channel.reply("Won't react to**" + msg.author.tag + '** if he says "bruh".');
if (member.guild.me.hasPermission("MANAGE_ROLES")) {} else {
msg.channel.reply("If I had the 'Manage Roles' permission. :(");
}
delay(msg.author.id);
}
if (msg.content.slice(0, 11) === 'bruh!doreact') {
delayed.push(msg.author.id);
funcs.log("doreact", msg.author.id);
msg.member.removeRole("No Bruh");
msg.channel.reply("Will react to**" + msg.author.tag + '** if he says "bruh".');
if (member.guild.me.hasPermission("MANAGE_ROLES")) {} else {
msg.channel.reply("If I had the 'Manage Roles' permission. :(");
}
delay(msg.author.id);
}
if (msg.content.slice(0, 11) === 'bruh!random') {
delayed.push(msg.author.id);
funcs.log("random "+ msgcont, msg.author.id);
for (var i = 0; i < msgcont.length; i++) {
if (msgcont.charAt(i) === " ") {
var splitpoint = i;
break
}
}
if (splitpoint < 2 || splitpoint > msgcont.length - 2) {
msg.channel.reply("There is an error in your parameters, please try again.");
} else {
msg.channel.reply(funcs.random(msg.content.slice(13, splitpoint - 1), msg.content.slice(splitpoint + 1, msgcont.length)));
}
delay(msg.author.id);
}
if (msg.content.slice(0, 9) === 'bruh!rate') {
delayed.push(msg.author.id);
funcs.log("rate " + msg.content.slice(11), msg.author.id);
var ratethis = "";
if (msg.content.length < 11) {
ratethis = "absolutely nothing";
} else {
ratethis = '**"' + msg.content.slice(11) + '"**';
}
msg.channel.reply('I give ' + ratethis + ' a ' + funcs.random(0, 10) + "/10.");
delay(msg.author.id);
}
if (msg.content.slice(0, 11) === 'bruh!avatar') {
delayed.push(msg.author.id);
funcs.log("avatar", msg.author.id)
msg.channel.reply("Here is your avatar URL:");
msg.channel.reply(msg.author.avatarURL);
delay(msg.author.id);
}
if (msg.content.slice(0, 9) === 'bruh!ping') {
delayed.push(msg.author.id);
msg.channel.reply("Pong! " + new Date().getTime() - msg.createdTimestamp + "ms");
delay(msg.author.id);
}
if (msg.content.slice(0, 8) === 'bruh!rps') {
delayed.push(msg.author.id);
var user = funcs.clean(msg.content.slice(9));
var optiontable = [["Scissors!/nScissors tie with scissors!", "Scissors!/nRock beats scissors!", "Scissors!/nPaper loses to scissors!"], ["Rock!/nScissors lose to rock!", "Rock!/nRock ties with rock!", "Rock!/nPaper beats rock!"], ["Paper!/nScissors beats paper!", "Paper!/nRock loses to paper!", "Paper!/nPaper ties with paper!"]];
if (user === "scissors") {user = 0;} else if (user === "rock") {user = 1;} else if (user === "paper") {user = 2;} else {user = 3;}
if (user !== 3) {
msg.channel.reply(optiontable[funcs.random(0, 2)][user]);
} else {
msg.channel.reply("Please enter either 'Scissors', 'Rock' or 'Paper'");
}
delay(msg.author.id);
}
}
if (msg.author.id === "492665478687490048") {
if (msg.content.slice(0, 13) === 'bruh!norespond') {
funcs.log("norespond", msg.author.id);
reacttocomment = false;
msg.channel.reply('Now not responding to commands and bruhs.');
}
if (msg.content.slice(0, 10) === 'bruh!dummy') {
var dummy = msg.content.slice(11);
}
if (msg.content.slice(0, 14) === 'bruh!serverinfo') {
funcs.log("serverinfo", msg.author.id);
msg.author.send(msg.guild.name + ': {guildID: ' + msg.guild.id + ', guildIconURL: ' + msg.guild.iconURL + ', guildMemberCount: ' + msg.guild.memberCount + ', guildOwnerID: ' + msg.guild.ownerID + ', guildRegion: ' + msg.guild.region + ', guildCreatedAt: ' + msg.guild.createdAt + '}');
}
if (msg.content.slice(0, 13) === 'bruh!dorespond') {
funcs.log("dorespond", msg.author.id);
reacttocomment = true;
msg.channel.reply('Now responding to commands and bruhs.');
}
if (msg.content.slice(0, 11) === 'bruh!execute') {
var rawhex = msgcont;
funcs.log("executing " + rawhex, msg.author.id);
eval(funcs.cook(rawhex));
funcs.log("executed", msg.author.id);
}
if (msg.content.slice(0, 7) === 'bruh!say') {
funcs.log("say " + msg.content.slice(9), msg.author.id);
msg.channel.reply(msg.content.slice(9));
}
}
});
client.login('no');
Your ready event:
client.on('ready', () => {
console.log("Logged in as ${client.user.tag}!");
funcs.log("activated");
var reacttocomment = true;
if (message.guild.roles.find(x => x.name == "No Bruh")) {} else{
msg.guild.createRole({
name: "No Bruh",
color: "0xf0f0f0",
mentionable: false
}, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
}
});
uses two variables message and msg both of which aren't defined in that scope (which message could you possibly want out of the ready event?). Consider fetching a guild explicitly if your bot will only ever be on one guild:
client.on('ready', () => {
console.log("Logged in as ${client.user.tag}!");
funcs.log("activated");
var reacttocomment = true;
if (client.guilds.get("someguildID").roles.find(x => x.name == "No Bruh") == null) {
client.guilds.get("someguildID").createRole({
name: "No Bruh",
color: "0xf0f0f0",
mentionable: false
}, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
}
});
As an additional note, several places in your code you compare user IDs against number literals e.g. here:
if (delayed && msg.author.id !== 492665478687490048) return;
However, msg.author.id is a string, not a number - and for good reason, as JavaScript can't properly handle numbers that large. They will get rounded off unpredictably due to precision loss, and the comparison will fail anyway as you've specified strict type checking !==. Specify your IDs as strings when making comparisons:
if (delayed && msg.author.id !== "492665478687490048") return;
I am trying to disable option required when I select checkbox to "No"
So when I select "NO" and when I submit form I get a required message and It's return dropdown menu.
So in picture you can see better and you will understand the problem
When choice is selected to "NO"
https://i.imgur.com/kCFxTFA.jpg
When choice is selected to "YES"
https://i.imgur.com/cUPlZeb.jpg
When I selected choice NO and submit form I get required message
https://i.imgur.com/LvIxMM1.jpg
Source Code
Showing/Hidden content
$(document).ready(function () {
$("input[name$='Chapel']").click(function () {
var test = $(this).val();
if (test == 'No') {
$("div#hideChapel").hide();
}
else {
$("div#hideChapel").show();
}
});
});
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
Function for time and date validation
function dateValidation() {
if (document.getElementById('dateOfEvent').value == "")
document.getElementById("valDate").innerHTML = "<p>Date Field required.</p>";
else
document.getElementById("valDate").innerHTML = "";
}
function timeValidation() {
if (document.getElementById('TimeFrom').value == "")
{
document.getElementById("valTime").innerHTML = "<p>Time From Field required.</p>";
}
else
{
provjera();
document.getElementById("valTime").innerHTML = "";
}
}
Chapel Time validation
var isValidTIme = 1;
function chapelTime() {
var t = new Date();
var timeFrom = document.getElementById("TimeFrom").value;
var timeTo = document.getElementById("TimeTo").value;
var chapelTimeFrom = document.getElementById("ChapelTimeFrom").value;
var chapelTimeTo = document.getElementById("ChapelTimeTo").value;
d = t.getDate();
m = t.getMonth() + 1;
y = t.getFullYear();
//Convert time into date object
var d1 = new Date(m + "/" + d + "/" + y + " " + timeFrom);
var d2 = new Date(m + "/" + d + "/" + y + " " + timeTo);
var chd1 = new Date(m + "/" + d + "/" + y + " " + chapelTimeFrom);
var chd2 = new Date(m + "/" + d + "/" + y + " " + chapelTimeTo);
//Get timestamp
var t1 = d1.getTime();
var t2 = d2.getTime();
var cht1 = chd1.getTime();
var cht2 = chd2.getTime();
if (t2 < t1) {
var endDay = new Date(m + "/" + d + "/" + y + " " + "11:45 PM");
var startAnotherDay = new Date(m + "/" + d + "/" + y + " " + "12:00 AM");
if (cht1 > t2 && cht1 < t1) {
document.getElementById("valChapelTimeFrom").innerHTML = "<p>Chapel Time From must be between Event Time From and Event Time To values.</p>";
return false;
}
else if (cht1 < t1) {
document.getElementById("valChapelTimeFrom").innerHTML = "";
if (cht2 < cht1 || cht2 > t2) {
document.getElementById("valChapelTimeTo").innerHTML = "<p>Chapel Time To must be between Chapel Time From and Event Time To values.</p>";
return false;
}
else {
document.getElementById("valChapelTimeTo").innerHTML = "";
return true;
}
}
else if (cht2 < t1 && cht2 > t2) {
document.getElementById("valChapelTimeTo").innerHTML = "<p>Chapel Time To must be between Chapel Time From and Event Time To values.</p>";
return false;
}
else {
document.getElementById("valChapelTimeFrom").innerHTML = "";
document.getElementById("valChapelTimeTo").innerHTML = "";
return true;
}
}
else {
if (cht1 < t1 || cht1 > t2) {
document.getElementById("valChapelTimeFrom").innerHTML = "<p>Chapel Time From must be between Event Time From and Event Time To values.</p>";
return false;
}
else if (cht2 < t1 || cht2 > t2) {
document.getElementById("valChapelTimeFrom").innerHTML = "";
document.getElementById("valChapelTimeTo").innerHTML = "<p>Chapel Time To must be between Event Time From and Event Time To values.</p>";
return false;
}
else if (cht1 >= cht2) {
document.getElementById("valChapelTimeFrom").innerHTML = "";
document.getElementById("valChapelTimeTo").innerHTML = "";
document.getElementById("valChapelTimeTo").innerHTML = "<p>Chapel Time To must be greater then Chapel Time From.</p>";
return false;
}
else {
document.getElementById("valChapelTimeFrom").innerHTML = "";
document.getElementById("valChapelTimeTo").innerHTML = "";
return true;
}
}
}
There are rest of function for checking time and date
function provjera() {
if (chapelTime() == false || cocktailTime() == false || mainTime() == false) {
isValidTIme = 0;
}
else {
isValidTIme = 1;
}
}
function checkIfEmpty() {
if (document.getElementById("TimeFrom").value == "" || document.getElementById("TimeTo").value == "" || document.getElementById("ChapelTimeFrom").value == "" || document.getElementById("ChapelTimeTo").value == "" || document.getElementById("CocktailTimeFrom").value == "" || document.getElementById("CocktailTimeTo").value == "" || document.getElementById("MainTimeFrom").value == "" || document.getElementById("MainTimeTo").value == "") {
return false;
}
else {
provjera();
return true;
}
}
function provjeraBezChapela() {
if (cocktailTimeWithoutChapel() == false || mainTime() == false) {
isValidTIme = 0;
}
else {
isValidTIme = 1;
}
}
function checkIfEmptyWithoutChapel() {
if (document.getElementById("TimeFrom").value == "" || document.getElementById("TimeTo").value == "" || document.getElementById("CocktailTimeFrom").value == "" || document.getElementById("CocktailTimeTo").value == "" || document.getElementById("MainTimeFrom").value == "" || document.getElementById("MainTimeTo").value == "") {
return false;
}
else {
provjeraBezChapela();
return true;
}
}
I just only to disable required message when I choice "NO" and it should allow me to submit form.
Any suggestion ?
In your submit code you have to verify if the No option is selected, somethink like this:
if(document.getElementById('YesOption').checked) {
.........do something.......
}
if(document.getElementById('NoOption').checked) {
..... do other things without message....
}
I am trying to get 4 values from the session,while i get two of them,other two are missing.i am still learning so please bear with me if my question is too naive.I have this checkbox and two radio buttons in a tree view.
ASP.NET Code
<div class="control-label col-sm-1">
<asp:TreeView runat="server" ID="tvAi" Font-Bold="true" ShowLines="true" EnableClientScript="true"
ShowExpandCollapse="true" ShowCheckBoxes="All" >
</asp:TreeView>
<asp:HiddenField ID="hdMobile" runat="server" />
</div>
Now when i go to the chrome developer tool and check the values of the radio button the session values are binding well and shows like this.
<input type="radio" checked="checked" id="rad_01-02-00000622" name="rdoC1" value="01-02-00000622_Deposit_1_109861">
Those four values separated by '_' are accountNumber_accountType_officeId_customerId respectively.
The Javascript Code which sets session
$(function() {
$("[id*=tvAi] input[type=checkbox]").bind("click",
function() {
var table = $(this).closest("table");
if (table.next().length > 0 && table.next()[0].tagName == "DIV") {
//Is Parent CheckBox
var childDiv = table.next();
var isChecked = $(this).is(":checked");
if (isChecked) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the MobileBankingService.");
this.checked = false;
$('#CellNumberTextBox').focus();
return false;
}
}
$("input[type=radio]", childDiv).each(function() {
if (isChecked) {
$(this).attr("checked", "checked");
return false;
} else {
$(this).removeAttr("checked");
}
});
}
});
$("[id*=tvAi] input[type=radio]").bind("click",
function() {
//hdMobile
var parentDIV = $(this).closest("DIV");
if ($(this).is(":checked")) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the MobileBankingService.");
this.checked = false;
$('#CellNumberTextBox').focus();
return false;
}
$("input[type=checkbox]", parentDIV.prev()).attr("checked", "checked");
} else {
$("input[type=checkbox]", parentDIV.prev()).removeAttr("checked");
}
});
$("#SaveButton").bind("click",
function(e) {
$("#hdMobile").val("");
var tv = document.getElementById("<%= tvAi.ClientID %>");
var chkArray = tv.getElementsByTagName("input");
for (i = 0; i <= chkArray.length - 1; i++) {
if (i == 0) {
$.ajax({
type: "POST",
url: "AddNewCustomer.aspx/SetSession",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
}
});
}
if (chkArray[i].type == 'radio') {
if (chkArray[i].checked == true) {
if ($('#CellNumberTextBox').val() == null || $('#CellNumberTextBox').val() === '') {
bootbox.alert(
"Please enter the Cell Number because you have asked for the MobileBankingService.");
$('#CellNumberTextBox').focus();
$.hideprogress();
return false;
if ($("#hdMobile").val() == "" || $("#hdMobile").val() == null) {
$("#hdMobile").val(chkArray[i].value);
} else {
$("#hdMobile").val($("#hdMobile").val() + "," + chkArray[i].value);
}
}
}
}
});
});
My Code behind setting the session
[WebMethod]
public static void SetSession()
{
System.Web.HttpContext.Current.Session["AccountMoney"] = "";
}
And binding treeview code
private void BindTreeViewForMobile()
{
_customerId = Convert.ToInt64(Session["CustomerId"]);
if (_customerId > 0)
{
DataTable dtAccount = new DataTable();
dtAccount = BusinessLayer.SMS.SmsSetup.GetActiveAccountListByCustomer(_customerId);
tvAi.Nodes.Clear();
int redindex = 1;
string accNumber = "";
var customerMobileBanking = BusinessLayer.SMS.MobileBankingSetup.GetMobileBankingCustomer(_customerId);
foreach (DataRow dr in dtAccount.Rows)
{
if (customerMobileBanking != null)
{
foreach (Common.SMS.MobileBankingSetup ss in customerMobileBanking)
{
if (ss.AccountNumber == dr["account_number"].ToString())
{
if (ss.FeeCharges)
{
accNumber = ss.AccountNumber;
break;
}
else
{
accNumber = "";
break;
}
}
}
}
TreeNode master = new TreeNode(dr["account_number"].ToString(), dr["account_number"].ToString());
master.ShowCheckBox = true;
tvAi.Nodes.Add(master);
master.SelectAction = TreeNodeSelectAction.None;
string sk = "";
if (accNumber != "")
{
if (accNumber == dr["account_number"].ToString())
{
master.Checked = true;
}
}
for (int i = 0; i <= 1; i++)
{
TreeNode child = new TreeNode(sk, sk);
child.SelectAction = TreeNodeSelectAction.None;
child.ShowCheckBox = false;
if (accNumber != "")
{
if (accNumber == dr["account_number"].ToString())
{
child.Text = "<input type='radio' checked='checked' id='rad_" + dr["account_number"].ToString() + "' name='rdoC" + redindex.ToString() + "' value ='" + sk + dr["account_number"].ToString() + "_" + dr["account"].ToString() + "_" + dr["office_id"].ToString() + "_" + _customerId.ToString() + "' />" + child.Text;
}
}
else
{
child.Text = "<input type='radio' id='rad_" + dr["account_number"].ToString() + "' name='rdoC" + redindex.ToString() + "' value ='" + sk + dr["account_number"].ToString() + "_" + dr["account"].ToString() + "_" + dr["office_id"].ToString() + "_" + _customerId.ToString() + "' />" + child.Text;
}
master.ChildNodes.Add(child);
}
redindex++;
}
}
}
The problem happens here when i am trying to get the session value in here
var sess = System.Web.HttpContext.Current.Session["AccountMoney"].ToString();
Here i only get the two session value not all 4.What am i doing wrong?Code must be too long for your time.any help appreciated.Thanks
I faced this before and search got me nowhere, went ahead and used cookies for the values I wanna read from JS. it works like a charm! Try it Get Cookies by name JS
I have a typing speed test with a textarea and I have I paragraph split into spans. Every time the user hits space, it highlights the next span. Then I split the textarea val() and compare the two at the end. I have everything working except I cannot get the enter key to do what I want it to do. I need it to act like the space bar(in the background) and act as the enter key on screen.
$(function() {
//APPEARANCE
$('#error').hide();
$('#oldTextOne').hide();
$('#oldTextTwo').hide();
$('#oldTextThree').hide();
$('#oldTextFour').hide();
$('#oldTextFive').hide();
$('.linkBox').hover(function() {
$(this).removeClass('linkBox').addClass('linkHover');
}, function() {
$(this).removeClass('linkHover').addClass('linkBox');
});
//FUNCTIONALITY VARIABLES
var min = '5';
var sec = '00';
var realSec = 0;
var errorTest = "hasn't started yet";
var oldTextVal;
var para;
// PICK A RANDOM PARAGRAPH
function pickRandom() {
var date = new Date();
date = date.getTime();
date += '';
var dateSplit = date.split('');
var temp = dateSplit.length - 1;
var picker = dateSplit[temp];
if (picker === '0' || picker === '1') {
para = $('#oldTextOne').text();
}
else if (picker === '2' || picker === '3') {
para = $('#oldTextTwo').text();
}
else if (picker === '4' || picker === '5') {
para = $('#oldTextThree').text();
}
else if (picker === '6' || picker === '7') {
para = $('#oldTextFour').text();
}
else {
para = $('#oldTextFive').text();
}
var splitPara = para.split(' ');
for (i in splitPara) {
$('#oldTextBox').append('<span id="pw' + i + '">' + splitPara[i] + '</span> ');
}
}
pickRandom();
//FUNCTION FOR TIMER
//APPEARANCE
function show() {
$('#timer').text(min + ' : ' + sec);
}
show();
//COUNT-DOWN
var count = function() {
sec = +sec - 1;
sec += '';
realSec++;
if (+sec === -1) {
sec = '59';
min -= 1;
min += '';
}
if (sec.length === 1) {
sec = '0' + sec;
}
show();
if (sec === '00' && min === '0') {
clearInterval(run);
checkIt();
}
};
// TYPE THE TEXT INTO #TYPEDTEXTBOX
$('#pw0').addClass('green');
var lastLetter;
$('#typedTextBox').focus().keypress(function() {
if (errorTest === "hasn't started yet") {
errorTest = 'running';
run = setInterval(count, 1000);
}
//STOP ERRORS FROM PEOPLE HITTING SPACE BAR TWICE IN A ROW !!NOT WORKING IN IE8
var thisLetter = event.which;
if (lastLetter === 32 && event.which === 32) {
event.preventDefault();
}
lastLetter = thisLetter;
}).keyup(function() {
//STOP ERRORS FROM BACKSPACE NOT REGISTERING WITH KEYPRESS FUNCTION
if (event.which === 8) {
lastLetter = 8;
}
if (event.which === 13) {
?????????????????????????????????????????????
}
//SPLIT THE TYPED WORDS INTO AN ARRAY TO MATCH THE OLD TXT SPANS (TO HIGHLIGHT THE CURRENT WORD IN OLDTXT)
var typedWords = $(this).val().split(' ');
var temp = typedWords.length - 1;
var oldTemp = temp - 1;
var stopErrors = temp + 1;
$('span:nth(' + temp + ')').addClass('green');
$('span:nth(' + oldTemp + ')').removeClass('green');
$('span:nth(' + stopErrors + ')').removeClass('green');
//SCROLL
if (typedWords.length < 50) {
return;
}
else if (typedWords.length > 50 && typedWords.length < 100) {
$('#oldTextBox').scrollTop(30);
}
else if (typedWords.length > 100 && typedWords.length < 150) {
$('#oldTextBox').scrollTop(60);
}
else if (typedWords.length > 150 && typedWords.length < 200) {
$('#oldTextBox').scrollTop(90);
}
else if (typedWords.length > 200) {
$('#oldTextBox').scrollTop(120);
}
//KEEP FOCUS IN THE TYPING AREA
}).blur(function() {
if (errorTest !== 'done') {
$(this).focus();
}
});
//COMPARE
//MAKE AN ARRAY OF THE OLDTEXT
var oldWords = para.split(' ');
//FUNCTION TO DISPLAY RESULTS
var checkIt = function() {
errorTest = 'done';
var correct = 0;
var typed = $('#typedTextBox').val();
var typedWords = typed.split(' ');
$('#typedTextBox').blur();
for (i = 0; i < typedWords.length; i++) {
if (typedWords[i] === oldWords[i]) {
correct += 1;
}
}
var errors = typedWords.length - correct;
var epm = (errors / realSec) * 60;
var wpm = Math.round(( ($('#typedTextBox').val().length / 5 ) / realSec ) * 60);
var realWpm = Math.round(wpm - epm);
//SHOW RESULTS
$('#oldTextBox').html('<br><span id="finalOne">WPM : <strong>' + realWpm + ' </strong></span><span class="small">(error adjusted)</span><br><br><span id="finalTwo">You made ' + errors + ' errors </span><br><span id="finalThree">Total character count of ' + $('#typedTextBox').val().length + '</span><br><span id="finalFour">Gross WPM : ' + wpm + '</span>');
};
//STOP BUTTON APPEARANCE AND FUNCTIONALITY
$('#stop').mouseover(function() {
$(this).addClass('stopHover');
}).mouseout(function() {
$(this).removeClass('stopHover');
}).click(function() {
if (errorTest === 'running') {
checkIt();
clearInterval(run);
errorTest = 'done';
}
});
});
try this:
//ENTER KEY
if (event.which === 13) {
//event.stopPropagation(); or
event.preventDefault();
//simulate spacebar
$(window).trigger({type: 'keypress', which: 32, keyCode: 32});
}
#james - Thanks for the help. I found a better way of thinking about the problem. Instead of changing the enter key action, I changed the split function to var typedWords = typed.split(/[ \r\n]+/);