This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

urgent help please  RSS feed

 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a text box say
<input type = "class" value = ""> on the value part i want to display say a random value from one of these mentioned below
CLIENT
BUS
TRAIN
FlIGHT
SHIP
How can i do this ,any snippet will be of great help
 
dagmar timler
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
String[] values = {"value1", "value2", value3"};
Random random = new Random();
int randomValue = random.nextInt(values.length);
%>
<input type="text" value="<%=values[randomValue] %>">
NOTES: You'll have to check that the random number generator doesn't generate values outside of the index values - I haven't tested this piece of code.
Then just insert your values in the String Array instead of value1, value2 etc.
 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanksssssss a lot Timler , i was fighting with a bigger code but ur snippet was very snappy and cool, thanks once again for ur help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!