PDA

Visualizza la versione completa : JavaScript comparare stringhe


jarno83
05-07-2008, 19:16
Salve a tutti

coma faccio a comparare due stringhe? ho scritto questo codice che non mi gira e non capisco il motivo



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">
function isSameString( s1, s2 )
{
if (s1 == s2)
{
alert("bene");
return true;
}
else
alert("sbagliato");
{
return false;
}
}

</script>
</head>
<body>
<input tabindex="3" name="s1" type="text" size="30" />
<input tabindex="3" name="s2" type="text" size="30" />
<input id="button" type="button" value="+" onclick= (isSameString(s1,s2)) />
</body>
</html>

grazie in anticipo :)

Samuele_70
05-07-2008, 20:57
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">
<!--
function isSameString( string1, string2 )
{
if(string1 == string2)
{
alert("bene");
}
else
{
alert("sbagliato");
}
}
//-->
</script>
</head>
<body>
<form>
<input tabindex="1" name="string1" type="text" size="30">
<input tabindex="2" name="string2" type="text" size="30">
<input type="button" id="button" value="+" onclick="isSameString( string1.value, string2.value);">
</form>
</body>
</html>

menphisx
06-07-2008, 14:43
Vorrei solo dire che c' la sezione javascript apposta. :stordita:

Loading