Get 3 names and show them sorted

0

I have a problem, it turns out that in my code, I have three names defined with the Array, but how can I request that my program first request the three names, that is, the user write 3 names whatever they are, sort alphabetically and then show them as an ordered result.

<html>
<head>
<title>Caracteres</title>
<meta charset="utf-8">
<style type="text/css">
    body    {
background-color:#DBDFDB; 
    }
</style>
</head>
<body>
<font color="#030303" face="georgia" size="5"> 
<center>
    <TABLE BORDER=3 width="1000" height="50">
    <TR><TD>
        <font face="georgia" size="30">
    <MARQUEE SCROLLAMOUNT=10 BEHAVIOR="alternate"><b>Programa para calcular caracteres</b></MARQUEE>
    </font>
    </TD></TR>
    </TABLE>

<script type="text/javascript">

var nombres = new Array("Andres", "Juan", "Carlos");
nombres.sort();

for (var i=0; i<nombres.length; i++) {
    document.write(nombres[i]);
}

</script>

</script>
</center>
</font>
</body>
</html>

bold text

    
asked by Graffters Skates 15.10.2017 в 01:47
source

1 answer

0

treat this instead of being automatic. I think the solution would be that in this code that I just wrote Guiding me of the ones you have

function validar(){
  var nombre1 = $('#nombre1').val();
  var nombre2 = $('#nombre2').val();
  var nombre3 = $('#nombre3').val();
  
  if(nombre1 == '' || nombre2 == '' || nombre3 =='' ){
    
    alert('llenar todo los campos requerido');
    
  }else{
  var nombres = new Array(nombre1, nombre2, nombre3);
  nombres.sort();

    for (var i=0; i<nombres.length; i++) {
      document.write(nombres[i]);
  }
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<font color="#030303" face="georgia" size="5"> 
<center>
    <TABLE BORDER=3 width="1000" height="50">
    <TR><TD>
        <font face="georgia" size="30">
    <MARQUEE SCROLLAMOUNT=10 BEHAVIOR="alternate"><b>Programa para calcular caracteres</b></MARQUEE>
    <input type='text' name='nombre1' id='nombre1'>
    <input type='text' name='nombre2' id='nombre2'>
    <input type='text' name='nombre3' id='nombre3'>
      
      <button type='button' onclick='validar()'>SEN VALIDATION</button
    </font>
    </TD></TR>
    </TABLE>
    
answered by 15.10.2017 в 02:09