Complex regular expression with validation rules and so on - javascript

Maybe I got killed here but I need to ask if this insane is possible through RegEx, see I have this Javascript/jQyery function for validates VAT number in Venezuela (RIF):
function(value) {
if (value === '') {
return true;
}
var $rif = value.val();
var $last_number = $rif.substr($rif.length - 1);
var $number = $rif.substr(0, 8);
$valid = /^([VEJPG]{1})([0-9]{9}$)/.test($rif_type + $rif);
if ($valid) {
if ($rif_type == "V") {
$sum = 1 * 4;
} else if ($rif_type == "E") {
$sum = 2 * 4;
} else if ($rif_type == "J") {
$sum = 3 * 4;
} else if ($rif_type == "P") {
$sum = 4 * 4;
} else if ($rif_type == "G") {
$sum = 5 * 4;
}
$n0 = $number.charAt(0) * 3;
$n1 = $number.charAt(1) * 2;
$n2 = $number.charAt(2) * 7;
$n3 = $number.charAt(3) * 6;
$n4 = $number.charAt(4) * 5;
$n5 = $number.charAt(5) * 4;
$n6 = $number.charAt(6) * 3;
$n7 = $number.charAt(7) * 2;
$sum += $n0 + $n1 + $n2 + $n3 + $n4 + $n5 + $n6 + $n7;
$mod = $sum % 11;
$last_val = 11 - $mod;
if ($last_val == 11 || $last_val == 10) {
$last_val = 0;
}
if ($last_number == $last_val) {
return true;
} else {
return false;
}
}
return false;
}
I'm asking if it's possible to write a RegEx to check the same and if so, how?
These are valid VAT numbers:
J298081775
J295809000
J298720620

Related

Javascript does not execute correctly

Good evening,
I am using Blockly to learn to programm.
In the exercise part of the code is not executed correctly. If "maandloon" is above > 2000, then there is a reduction of 25% on 'Kindergeld'. However if the result after the reduction is below 25 euro per child, then there is no reduction.
The problem is that calculation keeps using the 25% when maandloon >2000, even if the result afer reduction is below 25 euro per child.
This is my code:
var aantalKinderen, maandloon, kindergeld, kindergeldBasis, toeslag3ekind, toeslag5ekind, i;
do {
aantalKinderen=parseInt((parseFloat((output = window.prompt('Hoeveel kinderen?')) ? output : "")));
var blocktype_number = true;
if (output == null) {
window.alert("No empty input allowed");
break;
}
} while(isNaN(aantalKinderen));
do {
maandloon=(parseFloat((output = window.prompt('Wat is het maandloon?')) ? output : ""));
var blocktype_number = true;
if (output == null) {
window.alert("No empty input allowed");
break;
}
} while(isNaN(maandloon));
kindergeldBasis = 25;
toeslag3ekind = 12.5;
toeslag5ekind = 7.5;
kindergeld = kindergeldBasis * aantalKinderen;
if (aantalKinderen > 2) {
kindergeld = kindergeldBasis * aantalKinderen + (aantalKinderen - 2) * toeslag3ekind;
}
if (aantalKinderen > 4) {
kindergeld = kindergeldBasis * aantalKinderen + (aantalKinderen - 2) * toeslag3ekind + (aantalKinderen - 4) * toeslag5ekind;
}
if (maandloon <= 500) {
kindergeld = kindergeld * 1.25;
}
if (maandloon > 2000) {
kindergeld = kindergeld * 0.75;
} else {
if ((kindergeld * 0.75) / aantalKinderen < 25) {
kindergeld = kindergeld;
}
}
window.alert(String('Het kindergeld bedraagt ') + String(kindergeld)+'\n');
Can someone help me?
Thank you.
From what it sounds like you want to move your extra if check into the > 2000 statement. Otherwise it won't fire. Your if else statement is linear. It doesn't hit your else after > 2000 unless the conditional hasn't been matched by any of the previous if statements and the value is less than 2000. It does not run regardless or when the value was changed by a previous if condition.
var aantalKinderen, maandloon, kindergeld, kindergeldBasis, toeslag3ekind, toeslag5ekind, i;
do {
aantalKinderen=parseInt((parseFloat((output = window.prompt('Hoeveel kinderen?')) ? output : "")));
var blocktype_number = true;
if (output == null) {
window.alert("No empty input allowed");
break;
}
} while(isNaN(aantalKinderen));
do {
maandloon=(parseFloat((output = window.prompt('Wat is het maandloon?')) ? output : ""));
var blocktype_number = true;
if (output == null) {
window.alert("No empty input allowed");
break;
}
} while(isNaN(maandloon));
kindergeldBasis = 25;
toeslag3ekind = 12.5;
toeslag5ekind = 7.5;
kindergeld = kindergeldBasis * aantalKinderen;
if (aantalKinderen > 2) {
kindergeld = kindergeldBasis * aantalKinderen + (aantalKinderen - 2) * toeslag3ekind;
}
if (aantalKinderen > 4) {
kindergeld = kindergeldBasis * aantalKinderen + (aantalKinderen - 2) * toeslag3ekind + (aantalKinderen - 4) * toeslag5ekind;
}
if (maandloon <= 500) {
kindergeld = kindergeld * 1.25;
}
if (maandloon > 2000) {
kindergeld = kindergeld * 0.75;
if (kindergeld / aantalKinderen < 25) {
kindergeld = 25;
}
}
window.alert(String('Het kindergeld bedraagt ') + String(kindergeld)+'\n');

Check Persian Melli code in jQuery

How can I check Persian Melli code in jQuery
I have this code in c# language and work properly but when I converted this to jQuery didn't work.
I wrote this code but does not work :
function checkCodeMeli(obj) {
var code = obj.value;
var L = code.length;
if (L < 8 || parseInt(code, 10) == 0) {
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
return false;
}
code = ('0000' + code).substr(L + 4 - 10);
if (parseInt(code.substr(3, 6), 10) == 0) return false;
var c = parseInt(code.substr(9, 1), 10);
var s = 0;
for (var i = 0; i < 9; i++)
s += parseInt(code.substr(i, 1), 10 - 1) * (10 - i);
s = s % 11;
var t = (s < 2 && c == s) || (s >= 2 && c == (11 - s))
;
if (t == true)
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
else
$('#' + obj.id).css("background-color", "#fff").css("border", "1px solid gray");
return t;
return true;
}
Hi amir you can use this code to check Iranian national code:
function checkCodeMeli(obj) {
var input=obj.value;
if (!/^\d{10}$/.test(input))
{
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
return false;
}
var check = parseInt(input[9]);
var sum = 0;
var i;
for (i = 0; i < 9; ++i) {
sum += parseInt(input[i]) * (10 - i);
}
sum %= 11;
var isValid= (sum < 2 && check == sum) || (sum >= 2 && check + sum == 11);
if(!isValid){
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
}else{
$('#' + obj.id).css("background-color", "#38d043").css("border", "1px solid black");
}
return isValid;}
in JavaScript
console.log("1377456935 valid Code: "+checkMelliCode('1377456935'));
console.log("1377456938 Invalid Code: "+checkMelliCode('1377456938'));
function checkMelliCode(meli_code) {
if (meli_code.length == 10) {
if (meli_code == '1111111111' || meli_code == '0000000000' || meli_code == '2222222222' || meli_code == '3333333333' || meli_code == '4444444444' || meli_code == '5555555555' || meli_code == '6666666666' || meli_code == '7777777777' || meli_code == '8888888888' || meli_code == '9999999999') {
return false;
}
c = parseInt(meli_code.charAt(9));
n = parseInt(meli_code.charAt(0)) * 10 + parseInt(meli_code.charAt(1)) * 9 + parseInt(meli_code.charAt(2)) * 8 + parseInt(meli_code.charAt(3)) * 7 + parseInt(meli_code.charAt(4)) * 6 + parseInt(meli_code.charAt(5)) * 5 + parseInt(meli_code.charAt(6)) * 4 + parseInt(meli_code.charAt(7)) * 3 + parseInt(meli_code.charAt(8)) * 2;
r = n - parseInt(n / 11) * 11;
if ((r == 0 && r == c) || (r == 1 && c == 1) || (r > 1 && c == 11 - r)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
in C#
public bool IsValidNationalCode(string nationalcode)
{
if (string.IsNullOrEmpty(nationalcode)) return false;
if (!new Regex(#"\d{10}").IsMatch(nationalcode)) return false;
var array = nationalcode.ToCharArray();
var allDigitEqual = new[] { "0000000000", "1111111111", "2222222222", "3333333333", "4444444444", "5555555555", "6666666666", "7777777777", "8888888888", "9999999999" };
if (allDigitEqual.Contains(nationalcode)) return false;
var j = 10;
var sum = 0;
for (var i = 0; i < array.Length - 1; i++)
{
sum += Int32.Parse(array[i].ToString(CultureInfo.InvariantCulture)) * j;
j--;
}
var div = sum / 11;
var r = div * 11;
var diff = Math.Abs(sum - r);
if (diff <= 2)
{
return diff == Int32.Parse(array[9].ToString(CultureInfo.InvariantCulture));
}
var temp = Math.Abs(diff - 11);
return temp == Int32.Parse(array[9].ToString(CultureInfo.InvariantCulture));
}
Check this code (JavaScript)
console.log("1377456935 valid Code: "+checkMeliCode('1377456935'));
console.log("1377456938 Invalid Code: "+checkMeliCode('1377456938'));
function checkMeliCode(code) {
if (!/^\d{8,10}$/.test(code) || /^(0{8,10}|1{8,10}|2{8,10}|3{8,10}|4{8,10}|5{8,10}|6{8,10}|7{8,10}|8{8,10}|9{8,10})$/.test(code))
return false;
var L = code.length,
_ = 0;
for (i = 0; i < L - 1; i++)
_ += code.charAt(i) * (L - i);
_ %= 11;
return (code.charAt(L - 1) == ((_ < 2) ? _ : 11 - _))
}
This is solved my problem :
function checkCodeMeli(obj) {
var code = obj.value;
var L = code.length;
if (L < 8 || parseInt(code, 10) == 0) {
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
return false;
}
code = ('0000' + code).substr(L + 4 - 10);
if (parseInt(code.substr(3, 6), 10) == 0) return false;
var c = parseInt(code.substr(9, 1), 10);
var s = 0;
for (var i = 0; i < 9; i++)
s += parseInt(code.substr(i, 1), 10) * (10 - i);
s = s % 11;
var t = (s < 2 && c == s) || (s >= 2 && c == (11 - s));
if (t == false)
$('#' + obj.id).css("background-color", "#f8e8e8").css("border", "1px solid red");
else
$('#' + obj.id).css("background-color", "#fff").css("border", "1px solid gray");
return t;
return true;
}
Try Persian-tools an awesome javascript library for this matter and also many other useful functionalities.
import { verifyIranianNationalId, getPlaceByIranNationalId } from "persian-tools2";
verifyIranianNationalId("0067749828"); // true
verifyIranianNationalId("0684159415"); // false

equations with 3 numbers not displaying on HTML

I'm writing a math problem generator, but when I run it only equations with 2 numbers are displayed, anything more and it says "undefined" and refuses to show the answer. Here is the entire code(please note it is incomplete right now)
var type = 0;
var ans = 0;
function generatenumeral() {
var num = (Math.round(1000 * Math.random())) / 100;
var abs = Math.random();
if (abs < .4) {
num = num * -1;
}
console.log(num);
return (num);
}
function generatelength() {
var num = (Math.ceil(3 * Math.random()));
console.log(num);
return (num);
}
function generateSymbol() {
var sign = 0;
var num = (Math.round(12 * Math.random()));
console.log(num);
if (num === 0 || num == 1 || num == 9) {
sign = "+";
};
if (num === 2 || num == 3 || num == 10) {
sign = "-";
};
if (num === 4 || num == 5 || num == 11) {
sign = "/";
};
if (num === 6 || num == 7 || num == 12) {
sign = "*";
};
if (num == 8) {
sign = "+";
};
return (sign);
}
function WarmUpAr() {
var leng = generatelength();
if (leng == 1) {
var cool = twoNumb();
return (cool);
}
if (leng == 2) {
var cool = threNumb();
return (cool);
}
function twoNumb() {
var sign = 0;
var equation = 0;
var a = generatenumeral();
var b = generatenumeral();
var siggn = generateSymbol();
equation = a + " " + siggn + " " + b;
if (siggn == "+") {
ans = a + b;
}
if (siggn == "-") {
ans = a - b;
}
if (siggn == "/") {
ans = a / b;
}
if (siggn == "*") {
ans = a * b;
}
return (equation);
}
function threNumb() {
var sign = 0;
var a = generatenumeral();
var b = generatenumeral();
var c = generatenumeral();
var siggn = generateSymbol();
var siggnA = generateSymbol();
var equation = a + " " + siggn + " " + b +" "+ siggnA +" "+ c;
if (siggn.equals("+")) {
if (siggna.equals("+")) {
ans = a + b + c;
}
if (siggna.equals("-")) {
ans = (a + b) - c;
}
if (siggna.equals("/")) {
ans = a + (b / c);
}
if (siggna.equals("*")) {
ans = a + (b * c);
}
}
if (siggn.equals("-")) {
if (siggna.equals("+")) {
ans = a - b + c;
}
if (siggna.equals("-")) {
ans = (a - b) - c;
}
if (siggna == "/") {
ans = a - (b / c);
}
if (siggna.equals("*")) {
ans = a - (b * c);
}
}
if (siggn.equals("/")) {
if (siggna.equals("+")) {
ans = (a / b) + c;
}
if (siggna.equals("-")) {
ans = (a / b) - c;
}
if (siggna.equals("/")) {
ans = (a / b) / c;
}
if (siggna.equals("*")) {
ans = (a / b) * c;
}
}
if (siggn.equals("*")) {
if (siggna.equals("+")) {
ans = (a * b) + c;
}
if (siggna.equals("-")) {
ans = (a * b) - c;
}
if (siggna.equals("/")) {
ans = (a * b) / c;
}
if (siggna.equals("*")) {
ans = (a * b) * c;
}
}
// if (siggn == "^") {
// var ba = Math.round(b);
// var count = 0;
// for (count = 0; count < ba; count += 1) {
// var ab = ab * a;
// }
// ans = ab;
return (equation);
}
document.getElementById("ans").innerHTML = "not yet";
function arithmetic() {
type = 1;
document.getElementById("demo").innerHTML = WarmUpAr();
}
function preAlg() {
type = 2;
document.getElementById("demo").innerHTML = "hello";
}
function Alg() {
type = 3;
document.getElementById("demo").innerHTML = "This is cool";
}
function theAns() {
document.getElementById("ans").innerHTML = ans;
}
<p> "your warm up is....." </p>
<button onclick="arithmetic()">Arithmetic Warm Up </button>
<button onclick="preAlg()">PreAlg Warm Up </button>
<button onclick="Alg()">Algerbra Warm Up </button>
<p id="demo"></p>
<p>the answer is ....</p>
<button onclick="theAns()">answer</button>
<p id="ans"></p>
You forgot to close the WarmUpAr funtion,that's why you are getting undefined error
close this function WarmUpAr();
function WarmUpAr() {
var leng = generatelength();
if (leng == 1) {
var cool = twoNumb();
return (cool);
}
if (leng == 2) {
var cool = threNumb();
return (cool);
}
}
The reason threNumb() is failing is because your calling siggna.equals() in all your if statements. twoNumb() works because your using == instead of equals().
Also, in terms of calculating the answer to the equation, your doing it the hard way. In twoNumb() and threNumb() everything between where you set the 'equation' variable and where you return the 'equation' can be replaced with:
ans = eval(equation);

div inside if statement javascript

For some reason, the div tags are not displayed in the webpage when the program is run. I tested every other component and have figured out that the problem is that the setting of the value of the div tags is in an if statement. The only problem is that I do not know how to fix the problem and still have the program run the way I want it to.
<div id="answerDisplay"></div>
<div id="correctOrNot"></div>
<script>
var div
var div2
var rightAnswer
var problemNum =Math.floor((Math.random() * 3) + 1);
if (problemNum == 1){
rightAnswer = 14;
div = document.getElementById("answerDisplay");
div.textContent = "4 + 2 * (10 - 3 * 2) / 4 + 8 = ?";
}
else if (problemNum == 2){
rightAnswer = 8;
div = document.getElementById("answerDisplay");
div.textContent = "(6 - 3) * 2 + (3^2 - 5) / 2 = ?";
}
else if (problemNum == 3){
rightAnswer = 6;
div = document.getElementById("answerDisplay");
div.textContent = "5 - 3 + 4^2 / (8 - 4 / 2) = ?";
}
else if (problemNum == 4){
rightAnswer = 3;
div = document.getElementById("answerDisplay");
div.textContent = "5^2 - (6 * 2) * 2 * (5 - 2) = ?";
}
function checkRightAnswer (){
var answer = document.getElementById('Input').value
if (problemNum == 1 && answer == 14){
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum =Math.floor((Math.random() * 3) + 1);
}
else if (problemNum == 2 && answer == 8){
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum =Math.floor((Math.random() * 3) + 1);
}
else if (problemNum == 3 && answer == 6){
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum =Math.floor((Math.random() * 3) + 1);
}
else if (problemNum == 4 && answer == 3){
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum =Math.floor((Math.random() * 3) + 1);
}
else {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Incorrect, try again";
}
}
</script>
Your code seems to work fine. I don't see the input container included in the code snippet you provided. Perhaps you need to make sure the id is correct there? I cleaned up the code a bit:
var div, div2, rightAnswer, problemNum = Math.floor((Math.random() * 3) + 1);
if (problemNum === 1) {
rightAnswer = 14;
div = document.getElementById("answerDisplay");
div.textContent = "4 + 2 * (10 - 3 * 2) / 4 + 8 = ?";
} else if (problemNum === 2) {
rightAnswer = 8;
div = document.getElementById("answerDisplay");
div.textContent = "(6 - 3) * 2 + (3^2 - 5) / 2 = ?";
} else if (problemNum === 3) {
rightAnswer = 6;
div = document.getElementById("answerDisplay");
div.textContent = "5 - 3 + 4^2 / (8 - 4 / 2) = ?";
} else if (problemNum === 4) {
rightAnswer = 3;
div = document.getElementById("answerDisplay");
div.textContent = "5^2 - (6 * 2) * 2 * (5 - 2) = ?";
}
function checkRightAnswer() {
var answer = document.getElementById('Input').value;
if (problemNum === 1 && answer === 14) {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum = Math.floor((Math.random() * 3) + 1);
} else if (problemNum === 2 && answer === 8) {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum = Math.floor((Math.random() * 3) + 1);
} else if (problemNum === 3 && answer === 6) {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum = Math.floor((Math.random() * 3) + 1);
} else if (problemNum === 4 && answer === 3) {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Correct";
problemNum = Math.floor((Math.random() * 3) + 1);
} else {
div2 = document.getElementById("correctOrNot");
div2.textContent = "Incorrect, try again";
}
}
<div id="answerDisplay"></div>
<div id="correctOrNot"></div>
<input type="text" id="Input" />
Here is a way you would rewrite it to use an array of objects as ErikE suggested in his comment.
var questions = [
{
q: "4 + 2 * (10 - 3 * 2) / 4 + 8 = ?",
a: 14
},
{
q: "(6 - 3) * 2 + (3^2 - 5) / 2 = ?",
a: 8
},
{
q: "5 - 3 + 4^2 / (8 - 4 / 2) = ?",
a: 6
},
{
q: "5^2 - (6 * 2) * 2 * (5 - 2) = ?",
a: 3
}
],
currentQuestion, // the index of the current question will
// be stored here so we can look up the answer later
timerId,
doc = document,
elQuestion = doc.getElementById('question')
elAnswer = doc.getElementById('answer'),
elUserAnswer = doc.getElementById('user-answer'),
elCheck = doc.getElementById('check'),
displayQuestion = function (index) {
currentQuestion = index;
elQuestion.textContent = questions[index].q;
},
displayRandomQuestion = function () {
displayQuestion(Math.floor(Math.random() * questions.length));
},
removeAnswer = function () {
timerId = setTimeout(function () {
elAnswer.textContent = ''
}, 1000);
},
checkAnswer = function () {
var userAnswer = elUserAnswer.value;
clearTimeout(timerId);
// the '' + explicitly converts the .a to a string because userAnswer will be a string
// using the strict comparison operator (===) is a good habit to get into
if (userAnswer === '' + questions[currentQuestion].a) {
elAnswer.textContent = 'Correct!';
displayRandomQuestion();
} else {
elAnswer.textContent = 'Incorrect, try again';
}
removeAnswer();
};
elCheck.addEventListener('click', checkAnswer, false);
displayRandomQuestion();
Working jsfiddle
Doing it this way is shorter, cleaner and easier to maintain as well. Adding a new question/answer pair is as easy as adding another object to the array. No more copy/pasting if statements and other redundant code. In addition since there is only one place where each action is performed (questions/answers are displayed, the answer is checked, etc) if there is a bug with any of these features there is a single well defined place to look for the bug and you only have to fix it once instead of once for every question in your quiz.
The way I have abstracted lots of the work also makes it easier to extend the code in the future. For instance if you further abstract out the random number code:
getRandomIndex = function () {
return Math.floor(Math.random() * questions.length);
},
You can alter displayRandomQuestion so it will never repeat the same question twice in a row:
displayRandomQuestion = function () {
var index;
do {
index = getRandomIndex();
} while (index === currentIndex);
displayQuestion(index);
},
Or even ensure questions never repeat until all the questions have been asked:
askedIndexes = [],
displayRandomQuestion = function () {
var index;
do {
index = getRandomIndex();
} while (askedIndexes.indexOf(index) !== -1);
if (askedIndexes.length === questions.length - 1) {
askedIndexes = [];
}
askedIndexes.push(index);
displayQuestion(index);
},

How to use AJAX or JSON in this code?

I am creating a website application that allows users to select a seat, if it is not already reserved, and reserve it.
I have created a very round about way of getting the seats that are previously reserved using iFrames, however that was temporarily, now I need to make it secure and "proper javascript code" using proper practices. I have no clue what AJAX (or JSON) is, nor how to add it to this code, but it needs to get the file "seatsReserved"+this.id(that is the date)+"Que.html" and compare the string of previously reserved seats to see which class to make the element. If this is horrible, or if any of the other things could work better, I am open to criticism to everything. Thank you all!
Here is the javascript code:
A little side note, all of the if statements are due to different amount of seats in each row
<script>
var i = " 0 ";
var counter = 0;
var leng=0;
document.getElementById("Show1").addEventListener("click", changeDay);
document.getElementById("Show2").addEventListener("click", changeDay);
document.getElementById("Show3").addEventListener("click", changeDay);
function changeDay() {
var iFrame = document.getElementById("seatList");
iFrame.src = "seatsReserved" + this.id + "Que.html";
document.getElementById('date').innerHTML = this.id;
var seatsTaken = iFrame.contentWindow.document.body.innerHTML;
var k = 0;
let = 'a';
var lc = 0;
for (lc = 1; lc <= 14; lc++) {
if (lc == 1) {
leng = 28;
}
else if (lc == 2) {
leng = 29;
}
else if (lc == 3) {
leng = 32;
}
else if (lc == 4 || lc == 6 || lc == 12 || lc == 14) {
leng = 33;
}
else if (lc == 5 || lc == 13) {
leng = 34;
}
else if (lc == 8 || lc == 10) {
leng = 35;
}
else {
leng = 36;
}
for (k = 1; k <= leng; k++) {
if (seatsTaken.indexOf((" " +
let +k + " ")) <= -1) {
seat = document.getElementById(let +k);
seat.removeEventListener("click", selectedSeat);
}
else {
document.getElementById(let +k).className = "openseat";
document.getElementById(let +k).removeEventListener("click", doNothing);
}
}
let = String.fromCharCode(let.charCodeAt(0) + 1);
}
}
function loadChanges() {
var iFrame = document.getElementById("seatList");
var seatsTaken = iFrame.contentWindow.document.body.innerHTML;
var k = 0;
let = 'a';
var lc = 0;
var leng = 0;
for (lc = 1; lc <= 14; lc++) {
if (lc == 1) {
leng = 28;
}
else if (lc == 2) {
leng = 29;
}
else if (lc == 3) {
leng = 32;
}
else if (lc == 4 || lc == 6 || lc == 12 || lc == 14) {
leng = 33;
}
else if (lc == 5 || lc == 13) {
leng = 34;
}
else if (lc == 8 || lc == 10) {
leng = 35;
}
else {
leng = 36;
}
for (k = 1; k <= leng; k++) {
if (seatsTaken.indexOf((" " +
let +k + " ")) <= -1) {
seat = document.getElementById(let +k);
seat.addEventListener("click", selectedSeat);
seat.className = "openseat";
}
else {
document.getElementById(let +k).className = "notAvailible";
document.getElementById(let +k).addEventListener("click", doNothing);
}
}
let = String.fromCharCode(let.charCodeAt(0) + 1);
}
i = " 0 ";
counter = 0;
document.getElementById("seatString").innerHTML = i;
document.getElementById("getSeats").value = i;
document.getElementById("seatnums").innerHTML = counter;
}
i = document.getElementById("seatString").innerHTML;
counter = document.getElementById("seatnums").innerHTML;
function selectedSeat() {
var w = this.id;
var l = (" " + w);
var b = (" " + w + " ");
if (counter < 5) {
if (i.indexOf(b) <= 0) {
this.className = "closedseat";
i = i + b;
i = i.replace(" 0 ", " ");
document.getElementById("seatString").innerHTML = i;
document.getElementById("getSeats").value = i;
counter = counter + 1;
document.getElementById("seatnums").innerHTML = counter;
}
else if (i.indexOf(b) > 0) {
this.className = "openseat";
i = i.replace(b, "");
document.getElementById("seatString").innerHTML = i;
document.getElementById("getSeats").value = i;
counter = counter - 1;
document.getElementById("seatnums").innerHTML = counter;
}
}
else if (i.indexOf(b) > 0) {
this.className = "openseat";
i = i.replace(b, "");
document.getElementById("seatString").innerHTML = i;
document.getElementById("getSeats").value = i;
counter = counter - 1;
document.getElementById("seatnums").innerHTML = counter;
}
}
function doNothing() {
}
var rannum = Math.random() * 1000;
document.getElementById('getConfirmation').value = rannum;
</script>

Categories

Resources