jimfog Posted July 25, 2011 Share Posted July 25, 2011 The following is a code to recognize time formats such as this: 2:59 a.m. EDTfunction John (){ var range = window.getSelection().toString(); var hourformat=/(\d\d|\d)[:]\d\d\s([A][M]|[a][m]|[a][.][m])/g; var match = range.match(hourformat); if(range==match){alert("You chose(match)");} else{alert("You did not choose a time");}}; JJohn(); The regular expression works fines, what does not work fine is the alert box message .After the user has selected a time, i want an alert message to appear saying:"You chose(time selected goes here)"How am i going to achieve that?The syntax used-as can be seen above-is:{alert("You chose(match)");} It does not workAny suggestions?Summing it up, i want to combine in an alert message both a string and a variable()match. Link to comment Share on other sites More sharing options...
ShadowMage Posted July 25, 2011 Share Posted July 25, 2011 "It does not work" is a little vague, but I am assuming it means that the alert shows "You chose (match)" instead of, say "You chose (2:59 a.m. EDT)", correct?You need to take the variable out of the string, like:alert("You chose("+match+")"); Link to comment Share on other sites More sharing options...
jimfog Posted July 25, 2011 Author Share Posted July 25, 2011 "It does not work" is a little vague, but I am assuming it means that the alert shows "You chose (match)" instead of, say "You chose (2:59 a.m. EDT)", correct?You need to take the variable out of the string, like:alert("You chose("+match+")");Yes, correct.I will choose your version of the code and tell you if it works.Probably it will work. I tested various code combinations but not yours. Link to comment Share on other sites More sharing options...
jimfog Posted July 26, 2011 Author Share Posted July 26, 2011 It worked, thanks.Of course i removed the parentheses, i do not want them. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.