Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2007
    Messaggi
    42

    JavaScript comparare stringhe

    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

  2. #2
    codice:
    <!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>
    01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
    All errors are undocumented features waiting to be discovered.

  3. #3
    Vorrei solo dire che c'è la sezione javascript apposta.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.