marmite Posted May 18, 2007 Share Posted May 18, 2007 I'm a JS newbie, and still struggling on the same bit of code!! if (document.getElementById(instance) > 0) { This line isn't working. I've tried "!= null", "!=''" etc, nothing's working. So I think there are two possibles: 1) either "document.getElementById(instance)" is not correctly referring to the text inputs. 2) or something is wrong with my comparison operator (e.g. i shouldn't use !=null...) Can anyone tell me how to check the first thing, that it is referring correctly? Been working on this all week.. please help... Emma _______________________________________ Overrall purpose: I want a pop-up to alert the user that they haven't entered a value into the text inputs, when they click add to cart. (the alerts below are just for me to debug and this is in Test). Whole code: <script language="JavaScript" type="text/javascript"> <!-- function verify() { var i=0; var notblank=0; var numrows=<?php echo $numrows3; ?>; for (i;i<=numrows;i=i+1) { var instance="qty_" + i; if (document.getElementById(instance) > 0) { alert(document.getElementById(instance)); notblank=1; } } alert(notblank) if (notblank!=1) { alert("Please enter a quantity to add to the cart") return(false) } return(true) } //--> </script> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted May 18, 2007 Share Posted May 18, 2007 document.getElementById('') is just a reference to that specific element you want to add .value to the end to get the value of that element, if it has a value document.getElementById('instance').value != ''; etc Quote Link to comment Share on other sites More sharing options...
marmite Posted May 21, 2007 Author Share Posted May 21, 2007 Thanks - but every time I tried that, I had problems with the code actually completing. For example, in the below, the line alert("hello") does not execute. Any ideas why not? Many thanks Emma function verify() { var i=0; var notblank=0; var numrows=<?php echo $numrows3; ?>; for (i;i<=numrows;i=i+1) { var instance="qty_" + i; if (document.getElementById(instance).value !=0) { alert(document.getElementById(instance).value); notblank=1; } } alert("hello"); if (notblank!=1) { alert("Please enter a quantity to add to the cart") return(false) } return(true) } Quote Link to comment Share on other sites More sharing options...
marmite Posted May 21, 2007 Author Share Posted May 21, 2007 solved here: http://www.codingforums.com/showthread.php?p=568309&posted=1#post568309 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.