How to change (document.Check.validate.value) to integer from string

How is it that you can change within javascript in a JSP a value you get using something like this:

document.Check.validate.value

From a string to an integer. I have tried using the Integer.parseInt(document...)

This gives me a runtime error stating that Integer is not defined in the javascript I am trying to run.

PLEASE HELP....

Thank you!

[386 byte] By [moined_mogul] at [2007-9-26 2:07:44]
# 1
if(Integer.parseInt(document.Check.Barcode.value) == 2000)This is the line exactly that gives me the error.....says that Integer is not defined....
moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

This is the if statement below that I want to use. When I use it I am told that lastBarcode is not an object.

If I replace the document.Check.lastBarcode.value with "2000", it works the way it is suppose to by the user getting the alert if they enter a value for barcode that is less than 2000.

How is it that I can use lastBarcode like I do below but as an object?

Please help!!!!!!!!!!!

if(document.Check.Barcode.value > document.Check.lastBarcode.value)

{

alert("Sorry, you must enter a barcode that is greater than " + document.Check.lastBarcode.value);

return false;

}

moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Hi,change your if statement like this if(parseInt(document.Check.Barcode.value) == 2000)-priya
Priyam at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I am still getting the runtime error with this:

if((parseInt(document.Check.Barcode.value)) > (parseInt(document.Check.lastBarcode.value)))

{

alert("Sorry, you must enter a barcode that is greater than " + document.Check.lastBarcode.value);

return false;

}

moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
PLEASE HELP!!!!!!!!!!!!!!!!!
moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Try thisvar a = parseInt(document.Check.Barcode.value);var b = parseInt(document.Check.lastBarcode.value);if (a > b){}
Priyam at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I get the following error when I try to use the below code:

A Runtime Error has occured.

Error: 'document.Check.lastBarcode.value' is not an object

> Try this

>

> var a = parseInt(document.Check.Barcode.value);

> var b = parseInt(document.Check.lastBarcode.value);

>

> if (a > b)

> {

> }

>

>

moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

PLEASE HELP!!!!

This is the code in my JSP that I am trying to get to work:

<script language="JavaScript1.2">

var a = parseInt(document.Check.Barcode.value);

var b = parseInt(document.Check.largestBarcode.value);

if(a > b)

{

alert("Sorry, you must enter a barcode that is greater than the one you just entered");

return false;

}

}

</script>

<tr>

<input type="hidden" name="largestBarcode" value="<%=(adminFunctions.lastBarcode(libraryBook))%>">

This is my bean method that gets the largest number form my database:

public synchronized int lastBarcode (Resource resource)

{

Vector vResourceList= new Vector();

String[] alResourceList= null;

int nArraySize= 0;

double fValue= 0;

Double tempDouble;

int nBarcode= 0;

try

{

m_Statement=m_Connection.createStatement();

m_Results= m_Statement.executeQuery (m_strBarcode);

while (m_Results.next())

{

vResourceList.addElement(new String(m_Results.getString("scancode")));

}

m_Statement.close();

}

catch (SQLException queryFails)

{

System.out.println("Exception retrieving resource list " + queryFails.getMessage());

}

alResourceList = new String[vResourceList.size()];

//Moving into array to use in JSP page

vResourceList.toArray(alResourceList);

//Getting the size of the array

nArraySize= (alResourceList.length);

tempDouble= Double.valueOf(alResourceList[nArraySize-1]) ;

fValue= tempDouble.doubleValue() ;

nBarcode= (int)fValue;

return (nBarcode);

}

moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Hi,

if you are getting follow. error

Error: 'document.Check.lastBarcode.value' is not an object

then you have to check name of the form it should be 'Check' then name of your field it should be as it is

'lastBarcode'

It is case sensetive.

Check these things.

Priyam at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

I did notice that...and have corrected the name to largestBarcode from lastBarcode which was wrong.

I no longer get the error message but now seem to always get the alert message no matter what number I input. Even if I input 1000000, I am still getting that I need to enter a number larger than the one I entered. The largest number in the database now is 76.

??

moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
what is your barcode value?is it text field ?
Priyam at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
Yes, it is a text field.
moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
This is the tag:<TR><TD ALIGN="right"><B><div class="text">Barcode:</div></B></TD><TD> </TD><TD><INPUT TYPE="TEXT" NAME="Barcode" SIZE="30"></TD></TR>
moined_mogul at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14

i think follow pgm will help you.

<html>

<head>

<script>

function f1()

{

var a = parseInt(document.frm.x.value);

var b = parseInt(document.frm.t1.value);

if( a > b)

{

alert ("yes");

}

else

{

alert("no");

}

}

</script>

</head>

<body>

<form name = frm>

<input type = hidden name = x value = 100>

<input type = text name = t1 >

<input type = button value = click onclick = f1()>

</form>

</body>

</html>

Priyam at 2007-6-29 8:55:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
Does it have something to do with it being a text field?
moined_mogul at 2007-7-1 1:18:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16
have you tried my sample program ?
Priyam at 2007-7-1 1:18:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17
Thank you so much for your help!!! I relly appreciate it.Your program made me realize that I did not need quotes around:value=<%=(adminFunctions.lastBarcode(libraryBook))%Thank you so much!!!!
moined_mogul at 2007-7-1 1:18:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 18
you are welcome !
Priyam at 2007-7-1 1:18:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...