This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes doing a Integer.parseInt within javascript in a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doing a Integer.parseInt within javascript in a JSP" Watch "doing a Integer.parseInt within javascript in a JSP" New topic
Author

doing a Integer.parseInt within javascript in a JSP

Moined Mogul
Ranch Hand

Joined: Jul 11, 2001
Posts: 33
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!
if(Integer.parseInt(document.Check.Barcode.value) == 2000)
This is the line exactly that gives me the error.....says that Integer is not defined....
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

It's been some time since I coded Javascript, but Integer.parseInt(xxx) is a *Java* object, not a Javascript one.

If you want to check for numeric in javascript use isNaN(varName) and if you want to check if it's equal to a numeric value, just do a string comparison.
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
Integer.parseInt has not relation to JavaScript. It is a Java function.
You can use the JavaScript function parseInt to do the same thing however.
See http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1064173
S


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Moined Mogul
Ranch Hand

Joined: Jul 11, 2001
Posts: 33
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
Ranch Hand

Joined: Jul 11, 2001
Posts: 33
With this code I am always getting prompted to add a number that is great than the one I entered. Even if i enter 1000000 and the largest number in the database is 76.
???
shri ganesh
Greenhorn

Joined: Jul 24, 2001
Posts: 4
Hi,
try using
var a=parseInt(document.Check.Barcode.value,10)
var b=parseInt(document.Check.largestBarcode.value,10)
this should work!!
bye
shri
koushik konar
Greenhorn

Joined: Jul 29, 2001
Posts: 3
U can try out this
if(Integer.parseInt(document.Check.Barcode.value.trim()) == 2000)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doing a Integer.parseInt within javascript in a JSP
 
Similar Threads
Can't include .js file on jsp page controlled by front controller servlet
html:link and LookupDispatchAction
problem with integer values
won't let me input integer values
String to Integer conversion - why this error?