Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

javascript function not working when jsp load the first time but when refresh it works

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a jsp page that contain a javascript function to generate random alpha numeric characters. But the issue is when my page load the first time it does not work, however when i refresh the page it works fine. It is the same behaviour on all browsers.


Any suggestion why it is not working when my jsp page load for the first time?

Thanks a lot in advance.
 
Sheriff
Posts: 67403
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps, just perhaps, it might help to show us the code?
 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

my apologies for not showing the code earlier. Please see below javascript function:


This is how i am calling the function from my jsp page:

<body onload="codeSec1();">

Thanks a lot for the quick response.


 
Marshal
Posts: 25594
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And now, let's find out in what way does it "not work". (Apart from not being able to produce an upper-case Y, that is.)
 
Bear Bibeault
Sheriff
Posts: 67403
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This way of addressing elements:is antiquated and highly fragile. It may not be the cause of your issues (unlikely in any case), but it's a problem waiting to happen.

Assign an id to the element, and use document.getElementById() to fetch a reference to the element.



 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks for the suggestion, i have inserted an id as suggested in the last post and i have also include Y in the characters, just wanted to know if i have done it the right way:






Thanks again.
 
Bear Bibeault
Sheriff
Posts: 67403
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it working? Has that helped?
 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have not test it on all browsers but Internet Explorer 8 its working fine .

Thanks a lot for the help and suggestions.

Will let you know as soon as I test it on all browsers.

 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic