Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

JS script form question (comparison button)


OSC-Sevilla

Recommended Posts

i have a comparison form that is created at the top of the page. The user must check between 2 to 4 checkboxs for the form to pass the user to the comparison page. Originally this was a button, but now its a text link.

 

I am having problems with it. Its almost working but not quite:

 

 

The text link:

<p id="compare" style="display: block;"><a href="javascript: submitform();"><span></span><?php echo IMAGE_BUTTON_COMPARE;?></a></p>

</form>

 

The script:

 

<script language="javascript">

function validateButton() {

var getVal = $("input:checkbox:checked").length;

if (getVal < 2)

{

alert("Please choose at least 2 products to compare.");

return false;

}

if (getVal > 4)

{

alert("You can only compare 4 products at a time.");

return false;

}}

 

function submitform(){

document.compare.submit(); // takes us to the comparison page without validation.

};

</script>

 

------------------------------

 

changing the js at the bottom to:

 

function submitform(){

if(document.compare.onsubmit())

{//this check triggers the validations

document.compare.submit();

}

};

 

This ensures the validator alert pops up when the criteria is not met, but its not going to the intended page afterward if the chechboxes wiothin the form are check.

 

Looked all over the web and have not found a solution.

 

Any thoughts????

Link to comment
Share on other sites

SOLVED IT!!!!

 

 

<script language="javascript">

function validateButton() {

var getVal = $("input:checkbox:checked").length;

if (getVal < 2)

{

alert("Please choose at least 2 products to compare.");

return false;

}

if (getVal > 4)

{

alert("You can only compare 4 products at a time.");

return false;

}

document.compare.submit();

}

function submitform()

{

if(document.compare.onsubmit())

{

return true;

}

}

</script>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...