Ezilon.com - Target Your Audience, be Seen in Your Region

Need help in script of "Validate furnction".

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

He has: 26 posts

Joined: Dec 2006

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;
      }   
  } 
     }
}

&lt;/script&gt;

'

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's picture
ModeratorSponsor

He has: 545 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.

Hey! It compiles! Ship it!

He has: 301 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
--
"Old web developers don't die, they degrade gracefully..."