Jump to content

[SOLVED] Really basic.. how refer to text input??


marmite

Recommended Posts

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>

 

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)

}

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.