JSFiddle - React, Tailwind, and code Playground
HTML
<br/> <br/> <br/>
<p class="auto-style1"> Um conjunto de empresas ligadas umas às outras forma uma rede de relacionamentos. <br/>
Para medir o grau de conectividade da rede, use a calculadora abaixo:</p>
<!-- formulário -->
<form name="form1" id="form1" action="processa.php" method="get" onsubmit="return verifica(this);">
<table cellpadding="0" cellspacing="0" border="1" align="center">
<tr>
<td>Digite o número de empresas da rede.</td>
<td>
<input type="text" name="txt_empresas" id="txt_empresas" value=""/>
</td>
</tr>
<tr>
<td> Digite o número de conexões da rede.</td>
<td>
<input type="text" name="txt_conexoes" id="txt_conexoes" value=""/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="btn_calcular" id="btn_calcular" value="Calcular"/></td>
</tr>
</table>
</form>
CSS
body {
background-color:#CDC8B1;
}
p {
color: #660066;
font-size: x-large;
font-family: Calibri;
}
.auto-style1 {
text-align: center;
margin-right: 10px;
margin-left: 10px;
}
form {
align: center;
}
JavaScript
http://jsfiddle.net/su4rux5o/
//valida dados com javascript
function verifica(form1) {
var txtEmpresas = document.getElementById("txt_empresas"),
txtConexoes = document.getElementById("txt_conexoes");
if ( (txtEmpresas.value == "") || (!isNum(txtEmpresas.value)) || (Number(txtEmpresas.value) < 1) ) {
alert ("Preencha o número de empresas corretamente.");
txtEmpresas.focus();
return false;
}
if ( (txtConexoes.value == "") || (!isNum(txtConexoes.value)) || (Number(txtConexoes.value) < 1) ) {
alert ("Preencha o número de ligações corretamente.");
txtConexoes.focus();
return false;
}
return true;
}
function isNum(v) {
var ValidChars = "0123456789";
var isNumber=true;
var Char;
for (i=0; i< v.length && isNumber; i++) {
Char = v.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
return isNumber;
}