codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Sorting in ascending - random characters from user  abieroy at 23:43 on Thursday, June 08, 2006
 

hi am new in the forum and also javascript.

can someone help with some javascript tips.

i need to write a script that takes three numbers from user via prompt then output the numbers in ascending order.

this script coudl work for both (number and letters) but I would like to make one work first.

Many thanks

  Re: Sorting in ascending - random characters from user  Vallim at 10:52 on Wednesday, June 14, 2006
 

Hi abieroy,

I have given the code below to get 3 numbers in javascript using prompt and display them in ascending order.

<script language="javascript">
function Order()
{
var num1 = prompt("Enter Number1", "Type you first number here");
var num2 = prompt("Enter Number2", "Type you second number here");
var num3 = prompt("Enter Number3", "Type you third number here");
var inarray=new Array(3);
if((num1<num2)&&(num1<num3))
{
inarray[1]=num1;
if(num2<num3)
{
inarray[2]=num2;
inarray[3]=num3;
}
if(num3<num2)
{
inarray[2]=num3;
inarray[3]=num2;
}
}
if((num2<num1)&&(num2<num3))
{
inarray[1]=num2;
if(num1<num3)
{
inarray[2]=num1;
inarray[3]=num3;
}
if(num3<num1)
{
inarray[2]=num3;
inarray[3]=num1;
}
}
if((num3<num1)&&(num3<num2))
{
inarray[1]=num3;
if(num1<num2)
{
inarray[2]=num1;
inarray[3]=num2;
}
if(num2<num1)
{
inarray[2]=num2;
inarray[3]=num1;
}
}
for(var i=1;i<=3;i++)
{
document.write(inarray);
}
}
</script>

Please let me know if you have any doubts.

Regards,
Valli








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  form validation(arabic/persian language)
•  Function to check the pattern(i.e 1A-2B-3C)
•  function call from multiple rows
•  OpenFileDialog
•  Re: Sorting in ascending - random characters from user
•  Re: Date validation
•  How to use java in javascript-c
•  SQLException : returned refusing to connect
•  Dissappearing Menus


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006