Javascript craziness
-
I have a very simple javascript requirement that is proving to be problematic. here is the code:
function CleanDate(id) { var h = document.getElementById(id).value; h = h.replace(///g,"-"); document.getElementById(id).value = h; }
seems simple enough, as you can see i want to replace / with -. the problem is, in order to set / as the initial character, it comments out the rest of the line. even trying to escape it with \/ still comments everything after it. trying to use a vriable doesnt work, because using say t as a variable, with the value of "/", the replace sees t as a string literal rather than a variable. any suggestions? because of the requirements of the web app, i have to have a mm-dd-yyyy date format.______________________ Mr Griffin, eleventy billion is not a number...:wtf:
-
I have a very simple javascript requirement that is proving to be problematic. here is the code:
function CleanDate(id) { var h = document.getElementById(id).value; h = h.replace(///g,"-"); document.getElementById(id).value = h; }
seems simple enough, as you can see i want to replace / with -. the problem is, in order to set / as the initial character, it comments out the rest of the line. even trying to escape it with \/ still comments everything after it. trying to use a vriable doesnt work, because using say t as a variable, with the value of "/", the replace sees t as a string literal rather than a variable. any suggestions? because of the requirements of the web app, i have to have a mm-dd-yyyy date format.______________________ Mr Griffin, eleventy billion is not a number...:wtf:
okay, apparently even though vs2008 has a problem with this:
function CleanDate(id) { var h = document.getElementById(id).value; h = h.replace(/\//g,"-"); document.getElementById(id).value = h; }
IE and firefox do not :)______________________ Mr Griffin, eleventy billion is not a number...:wtf: