Javascript replace works in console, not in code -
i've been trying setup little booking scheme i'm stuck. basically, add together seat numbers want booked string eg (a22~b20~f10). when seat deselected needs removed string. have tried using .replace no avail, in console.
i tried code below. works brilliantly in console, not @ in code.
seatnumberstobook.split(seatnumber+"~").join("");
the total function here
var seatnumberstobook = ""; function calcseats(calc, seatnumber){ if(amountseatstobebooked != 0 && seatnumber != "nan" && calc == "-1"){ seatnumberstobook = seatnumber + "~" + seatnumberstobook; } if(calc == "+1"){ //remove seatnumberstobook array seatnumberstobook.split(seatnumber+"~").join(""); console.log(seatnumber); } // despite removing seat number array, still must check in array see if seatnumber has been recorded amountseatstobebooked = eval(amountseatstobebooked + calc); $("#remainingseatstobebooked").html(amountseatstobebooked); console.log(seatnumberstobook); homecoming amountseatstobebooked; }
thanks lot in advance!!
you split() join() don't assign result seatnumberstobook, seatnumberstobook still old value
javascript replace
No comments:
Post a Comment