galvin Posted May 13, 2009 Share Posted May 13, 2009 I run some Ajax code that brings back a reply that is equal to "1990". The php page I call literally says... echo "1990"; I have an arrray called "answer" where the element in the "1" position is equal to "1990"... var classicmovies = new Array("1986","1990"); However, when I run the code below, it does not work. I think it's seeing reply as 1990 rather than "1990", so it's not a match. As a test, i changed the word reply in the code below to be "1990" (with quotes) and then the code ran fine. I'm guessing something is up with how the date 1990 is being handled as a number instead of a string? Is there a way to throw quotes around the word reply below? I'm at a loss here. Anyone know what's wrong? function compare(reply){ if (answer[1] == reply) { //do this } } Quote Link to comment https://forums.phpfreaks.com/topic/157909-javascript-datesstring/ Share on other sites More sharing options...
xtopolis Posted May 13, 2009 Share Posted May 13, 2009 What about parsing it as an int? var reply = parseInt(xhro.repsonseText); Quote Link to comment https://forums.phpfreaks.com/topic/157909-javascript-datesstring/#findComment-832975 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Like in PHP, JavaScript doesn't care if you have quotes around numbers if they match. Example - "1900" == 1900 in JavaScript. You'll have to post more code for me to know what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/157909-javascript-datesstring/#findComment-832981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.