Need help in script of "Validate furnction".
Hi,
I implement this JavaScript “Validation code” on to my website, but it’s not work and didn’t give me an error as well. In this code QTY is a quantity of the product, which customer should select at least 1.
<script>
function validate() {
var qtyFields = document.getElementsByTagName('input');
for(i=0; i<qtyFields.length; i++) {
if(qtyFields[i].className == 'qty') {
if(qtyFields.value < 1) {
alert("Please insert a value from 1 to 99.");
return false;
}
}
}
}
</script>
HTML code is:
<!--- qty is a dynamic value and will change dynamically, for example some pages qty hold only 1
product and some time qty hold more than 1 products --->
<html>
sku_qty = "#FORM.Qty#"
<form>
<input class="qty" name="qty" type="text" value="0" size="2">
</form>
</html>
Could any one help me in this code?
Thanks
pr0gr4mm3r posted this at 03:08 — 5th July 2007.
He has: 1,502 posts
Joined: Sep 2006
Did you copy this from somewhere, or did you write it? Your <script> tag should actually be <script type="text/javascript">. That may be the problem if it's not running.
webwiz posted this at 18:12 — 5th July 2007.
He has: 629 posts
Joined: May 2007
As far as I can make out, there is nothing in your page or your script to actually trigger the function you have there. You need to add an event in order for the script to run.
What do you want to happen in order to run this code? Surely there's more to your HTML? A link to the page would help.
(FWIW - Yahoo JavaScript expert Douglas Crockford reckons that no browser on earth takes any notice of the "type" attribute on the "script" tag, so you are okay as far as that goes.)
Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.