I'm trying to do some form validation (one field, needs to be 15 digits and numeric only) and I have the validation working on a php page I cannot seem to use it on my e-junkie form/cart.



The meat of it is below:



<script Language="Javascript">

<!--

// The previous line hides the script from old browsers that cant interpret it





function digitvalidation(entered, min, max, alertbox, datatype)

{

// Digit-Validation (c) Henrik Petersen / NetKontoret

// Explained at www.echoecho.com/jsforms.htm

// Please do not remove the this line and the two lines above.

with (entered)

{

checkvalue=parseFloat(value);

if (datatype)

{smalldatatype=datatype.toLowerCase();

if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};

}

if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)

{if (alertbox!="") {alert(alertbox);} return false;}

else {return true;}

}

}



function emptyvalidation(entered, alertbox)

{

// Emptyfield-Validation (c) Henrik Petersen / NetKontoret

// Explained at www.echoecho.com/jsforms.htm

// Please do not remove the this line and the two lines above.

with (entered)

{

if (value==null || value=="")

{if (alertbox!="") {alert(alertbox);} return false;}

else {return true;}

}

}



function formvalidation(thisform)

{

with (thisform)

{

if (emptyvalidation(model,"Please enter your phone model")==false) {model.focus(); return false;};

if (emptyvalidation(imei,"Please enter your 15 digit IMEI number.")==false) {imei.focus(); return false;};

if (digitvalidation(imei,15,"Your IMEI is a 15 digit number. Please enter it correctly","Your IMEI is a 15 digit number. Please enter it correctly")==false) {imei.focus(); return false;};

}

}



// The next line causes oldfashion browsers to start interpreting the code again.

//-->

</script>



It requires "onsubmit="return formvalidation(this)"" as part of the "form action" line.....this works perfectly on my php page but it doesn't appear to do anything with my e-junkie form/cart/product.



Anyone else doing forms with validation with e-junkie?

  • created

    Jun '13
  • last reply

    Jun '13
  • 1

    reply

  • 1.3k

    views

  • 2

    users

  • 2

    links

Hm, since our standard Add to Cart code for items using Variations/Variants uses an onClick="javascript:return EJEJC_lc(this.parentNode);" attribute in the cart button's <image type="image"> tag to submit values to the cart, rather than an onSubmit= attribute on the form itself, you might try removing the onSubmit and changing our standard onClick so it calls your validator script, then that script would in turn call EJEJC_lc() if the submission passes the validation.



If you need further assistance with that, we can recommend the competent, E-junkie-experienced developers listed in our directory here:

http://www.e-junkie.com/ej/developer-directory.htm