javascript - replace method not working -
i'm trying write credit card validation script using luhn algorithm, can't manipulate string input right myself started. trying take out hyphens , spaces string keeps saying in debugger function has no replace method? im not programmer, trying through class.....
here's code, there might line or 2 in there testing purposes forgot remove.
<script type="text/javascript"> function fixstring(){ //get credit card number var ccnumber = document.getelementbyid("ccnumber"); //remove hyphens , spaces var ccnumber = ccnumber.replace(/-/g, ""); //.replace(/\n/g, ""); show.innerhtml = ccnumber.value; } </script> <body> <form action="#"> <p><label>enter credit card number here:<input id="ccnumber" type="text"> </label> <input value="validate" onclick="fixstring()" type="button"> </p> </form> <p id="show"></p> </body>
you have right ideas , on right track!
var ccnumber = document.getelementbyid("ccnumber");
this gets element. doesn't value.
you want this.
var ccnumber = document.getelementbyid("ccnumber").value;
then here, show.innerhtml = ccnumber.value;
, remove .value
since ccnumber
string.
Comments
Post a Comment