Forum Moderators: coopster
strList is the whitelist / blacklist
bAllow = true is for whitelist, false is for blacklist
function limitinput(evt, strList, bAllow)
/*Limits the input to strList. If bAllow is true, then
only allow what is in strList. If bAllow is false,
then do not allow what is in strList.*/
{
var charCode = evt.keyCode;
if (charCode==0)
{
charCode = evt.which;
}
var strChar = String.fromCharCode(charCode);
/*controlArray holds the ASCII codes for valid
control commands (BS, CR, LF, etc)*/
var controlArray = Array(0, 8, 9, 10, 13, 27);
var intOut = 0;if (bAllow==true)
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)!=-1))
/*Valid*/
{
return true;
}
else
{
return false;
}
}
else
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)==-1))
{
return true;
}
else
{
return false;
}
}
}
<script language="javascript">
bAllow = truefunction limitinput(evt, strList, bAllow)
/*Limits the input to strList. If bAllow is true, then
only allow what is in strList. If bAllow is false,
then do not allow what is in strList.*/
{
var charCode = evt.keyCode;
if (charCode==0)
{
charCode = evt.which;
}
var strChar = String.fromCharCode(charCode);
/*controlArray holds the ASCII codes for valid
control commands (BS, CR, LF, etc)*/
var controlArray = Array(0, 8, 9, 10, 13, 27);
var intOut = 0;
if (bAllow==true)
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)!=-1))
/*Valid*/
{
return true;
}
else
{
return false;
}
}
else
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)==-1))
{
return true;
}
else
{
return false;
}
}
} </script><?php
/*** Add-to-Cart Button ***/
if (USE_AS_CATALOGUE!= '1' && $product_price!= "" &&!stristr( $product_price, $PHPSHOP_LANG->_PHPSHOP_PRODUCT_CALL )) {
$form_addtocart = "<form action=\"". $mm_action_url ."index.php\" method=\"post\" name=\"addtocart\" id=\"addtocart".$i."\">\n
<label for=\"quantity_".$i."\">".$PHPSHOP_LANG->_PHPSHOP_CART_QUANTITY.":</label>\n
<input id=\"quantity_".$i."\" class=\"inputbox\" type=\"text\" size=\"3\" name=\"quantity\" value=\"1\" />
<input onKeyPress=\"javascript:return limitinput(event, '0123456789', true);\" class=\"button\" type=\"submit\" name=\"submit\" value=\"".$PHPSHOP_LANG->_PHPSHOP_CART_ADD_TO."\" />\n
<input type=\"hidden\" name=\"category_id\" value=\"". @$_REQUEST['category_id'] ."\" />\n
<input type=\"hidden\" name=\"product_id\" value=\"". $db_browse->f("product_id") ."\" />\n
<input type=\"hidden\" name=\"page\" value=\"shop.cart\" />\n
<input type=\"hidden\" name=\"func\" value=\"cartadd\" />\n
<input type=\"hidden\" name=\"Itemid\" value=\"$Itemid\" />\n
<input type=\"hidden\" name=\"option\" value=\"com_phpshop\" />\n
</form>\n";
<script language="javascript">
bAllow = truefunction limitinput(evt, strList, bAllow)
/*Limits the input to strList. If bAllow is true, then
only allow what is in strList. If bAllow is false,
then do not allow what is in strList.*/
{
var charCode = evt.keyCode;
if (charCode==0)
{
charCode = evt.which;
}
var strChar = String.fromCharCode(charCode);
/*controlArray holds the ASCII codes for valid
control commands (BS, CR, LF, etc)*/
var controlArray = Array(0, 8, 9, 10, 13, 27);
var intOut = 0;
if (bAllow==true)
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)!=-1))
/*Valid*/
{
return true;
}
else
{
return false;
}
}
else
{
if (charCode==8 ¦¦ charCode==9 ¦¦ charCode==37 ¦¦ charCode==39 ¦¦ charCode==46 ¦¦ charCode==116 ¦¦ (strList.indexOf(strChar)==-1))
{
return true;
}
else
{
return false;
}
}
} </script><?php
/*** Add-to-Cart Button ***/
if (USE_AS_CATALOGUE!= '1' && $product_price!= "" &&!stristr( $product_price, $PHPSHOP_LANG->_PHPSHOP_PRODUCT_CALL )) {
$form_addtocart = "<form action=\"". $mm_action_url ."index.php\" method=\"post\" name=\"addtocart\" id=\"addtocart".$i."\">\n
<label for=\"quantity_".$i."\">".$PHPSHOP_LANG->_PHPSHOP_CART_QUANTITY.":</label>\n
<input onKeyPress=\"javascript:return limitinput(event, '0123456789', true);\" id=\"quantity_".$i."\" class=\"inputbox\" type=\"text\" size=\"3\" name=\"quantity\" value=\"1\" />
<input class=\"button\" type=\"submit\" name=\"submit\" value=\"".$PHPSHOP_LANG->_PHPSHOP_CART_ADD_TO."\" />\n
<input type=\"hidden\" name=\"category_id\" value=\"". @$_REQUEST['category_id'] ."\" />\n
<input type=\"hidden\" name=\"product_id\" value=\"". $db_browse->f("product_id") ."\" />\n
<input type=\"hidden\" name=\"page\" value=\"shop.cart\" />\n
<input type=\"hidden\" name=\"func\" value=\"cartadd\" />\n
<input type=\"hidden\" name=\"Itemid\" value=\"$Itemid\" />\n
<input type=\"hidden\" name=\"option\" value=\"com_phpshop\" />\n
</form>\n";
}