Visualizzazione dei risultati da 1 a 10 su 10
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    277

    Evento onclick su righe di testo

    Ciao ragazzi.

    Domanda semplicissima:

    Io ho in una tabella:

    <td>Pippo</td>


    Vorrei associare a quella riga l'evento OnClick, nel senso che se clicco una qualsiasi parte di quella riga, viene scatenato l'onclick per far partire js e via discorrendo...

    Come posso fare?

    Grazie mille,
    DAvid.

  2. #2
    Cosa intendi con riga? Tutta la <tr> o solo la scritta Pippo?

    Nel secondo caso si fa cosi':

    <td onclick="miafunzione()">Pippo</td>

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    277
    Ok, ti ringrazio.

    Allora se ho:
    Codice PHP:
    function SetActiveID_2(me,ID){
        var 
    id=(me.name.substr(12,14));
        
    document.getElementById("nasc_new").value me.name;

    e poi:

    Codice PHP:
    echo   '<td id= "ID" onclick="SetActiveID_2(this,ID);" onFocus="SetActiveID_2(this,ID); "  name ="'.$USER['USERNAME'].'">' .$USER['USERNAME']. ' </td>'
    E QUINDI:

    Codice PHP:
    <form action="pippo.html" method="GET">
    <
    input  type="text" id="nasc_new" name="idchanged" value="">
    <
    input type="submit">
    </
    form
    perché non mi funziona?

  4. #4
    E' sempre cortesia postare il codice HTML come lo vedi sul browser e non PHP (non puoi supporre che tutti conoscano PHP)

    comunque vedo questo:

    SetActiveID_2(this,ID)

    Ma cos'e' questo ID che vorresti passare alla funzione? Visto cosi' sembrerebbe una variabile. Ma dubito che quella fosse la tua intenzione.

    In realta' la tua funzione SetActiveID_2 non fa uso del parametro ID, quindi perche' usarlo???

    al limite dovresti passarlo tra apici singoli comunque, in questo modo:

    SetActiveID_2(this,'qualcosa')

    Infine sappi che alcuni doctype non permettono di usare l'attributo onclick e onchange se non sugli input e i tag <a>. Per cui dai un occhio al doctype

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    277
    Si, in effetti è come dici.

    Ho quindi cambiato il document type, però il mio problema si è spostato sull'associare il problema alla riga, ovvero al tr.

    QUi sotto il codice:

    Codice PHP:
    <!doctype html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <
    HTML>  <HEAD>
         <
    TITLE>
          
    SSP Version 0.0 USER d AnnoND Azienda ND      </TITLE>

        <
    meta name=generator content="Prove e test ssp">
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta name="keywords" content="walt disney fumetti topolino paperino immagini italia francobolli zio paperone barks scarpa gottfredson cavazzano rosa">

    <
    link rel="stylesheet" href="../../COMMON/CSS/top.css" type="text/css"><link rel="shortcut icon" href="../../COMMON/ICONS/test.ico" type="image/x-icon">    
    <
    script language="Javascript">


    var 
    pars="";

    function 
    AIC(me){ //AddIDToidchanged
    me.style.background "#0AFF00"//background-color to green to let user know must use ajax
    var melength=me.name.length// had to use length bec autoid can get larger than just 1 ,2,3,4, or 5 digits.
    var id=(me.name.substr(3,melength)); // will always be 3(f00) then autoid digits.
    if (id){
    var 
    str=document.getElementById("idchanged").value// if not sure how works then unhide the field on the form
    if (str==""){
    document.getElementById("idchanged").value=str id;
    document.getElementById("nascosto").value=str id;
    }else{
    if (!
    str.match(id)){
    document.getElementById("idchanged").value=str ","  id;
    document.getElementById("nascosto").value=str ","  id;
    }}
    // this added for ajax

    if (pars==""){
    pars=me.name "=" me.value;
    }else{
    pars=pars+"&"+me.name+"="+me.value;
    }}
    }


    function 
    SetActiveID(me,form){
        
    //alert (me);
        
    var id=(me.name.substr(12,14));
        
    form.activeid.value=me.name;
        
    document.getElementById("nascosto").value=me.name;
    }
    function 
    SetActiveID_2(me){
        
    //alert (me);
        
    var id=(me.name.substr(12,14));
        
    //form.activeid.value=me.name;
        //elem = document.getElementById(ID).value;
        
    document.getElementById("nasc_new").value me.name;
    }
     function 
    hasClass(obj) {
         var 
    result false;
         if (
    obj.getAttributeNode("class") != null) {
             
    result obj.getAttributeNode("class").value;
         }
         return 
    result;
      }   






    </SCRIPT>
    </head>

    <form method=post action="./../ABILITAZIONE/save.php"><table id = "playlist"  frame = box border = 1 cellspacing="0">
    <tr><td width="0%"></td> 
    <td>[b]Legal entity enabling [/b]</td>
     <td>[b]Roles[/b]</td>
     <td>[b]Password modification[/b]</td>
      <td>[b]Other user details[/b]</td>
       <td>[b]Login name[/b]</td> 
       <td>[b]First name[/b]</td> 
       <td>[b]Last name[/b]</td> 
       <td>[b]E-mail address[/b]</td>
       <td>[b]Enabled[/b]</td>
       </tr>

    <tr><div id= "ID" onclick="SetActiveID_2(this,id);" onFocus="SetActiveID_2(this,ID); "  name ="062be1fc-ca11-102a-9eae-71cfbb3cf82a">
    <td width="0%"><input type="hidden" name="USER_ID[0]" value="062be1fc-ca11-102a-9eae-71cfbb3cf82a" disable = "disabled"></td>
    <td><input type="submit" name="LE_AB[0]"  value = "Abilitazione aziende"></td>
    <td><input type="submit" name="ROLES_AB[0]"  value = "Ruoli"></td>
    <td><input type="button" name = "Mod_pwd"
    onClick = window.open("./../PASSWORD/password.php?USER_ID=062be1fc-ca11-102a-9eae-71cfbb3cf82a","newwin","scrollbars=no,status=no,resizable=yes,top=300,left=150,width=300,height=750") value = "Password modification " ></td>
    <td><input type="button" name = "Mod_dett"
    onClick = window.open("usr_details.php?USER_ID=062be1fc-ca11-102a-9eae-71cfbb3cf82a","newwin","scrollbars=no,status=no,resizable=yes,top=300,left=150,width=300,height=750") value = "Other user details " ></td>
    <td>david </td>
    <td>d</td>
    <td>d</td>
    <td>cicici</td>
    <td><textarea rows="1" cols="1"class="boldblue"style="font:arial;"name="062be1fc-ca11-102a-9eae-71cfbb3cf82a"WRAP="virtual" onchange="AIC(this)" onclick="SetActiveID(this,this.form);"onFocus="SetActiveID(this,this.form); "></textarea></td>
    <td> <input type= 'checkbox' name='FLG_ROLE_CODE_EDIT'></td></div></tr>
    </table>
    IDs Changed<input  id="idchanged" name="idchanged" value="">

    Active Element's Name:<input name="activeid">




    </form>

    <form action="pippo.php" method="POST">
    <input  type="text" id="nascosto" name="idchanged" value="">
    <input type="submit">
    </form>
    </form>

    <form action="pippo.php" method="POST">
    <input  type="text" id="nasc_new" name="idchanged" value="">
    <input type="submit">
    </form>


    </body>
    </HTML> 
    Sia che la riga la 'taggi' con div, che con a, lo script non mi funziona. Continua invece a funzionarmi sulla singola cella (la textarea...). Come si può far funzionare? :master:

  6. #6
    david77, non puoi improvvisare andando per tentativi!!!

    Innanzitutto non si puo' mettere un div direttamente dentro un tr

    L'html vuole che dentro una tr ci vadano delle td e - se mai - dentro queste ci metti dei div

    Poi ti avevo detto di sistemare quel

    SetActiveID_2(this,id)

    non si capisce cosa ti serva quel secondo parametro. Visto che non lo chiami nella funzione. Fortunatamente per te javascript sottointende che volgia passare l'id del div e non segnala errori; come se tu avessi scritto

    codice:
    SetActiveID_2(this, this.id)
    Ma se non intendi usarlo toglilo.

    Infine non e' definito name come proprieta' dell'oggetto div ma come attributo
    Per cui se vuoi leggerlo non puoi fare

    codice:
    me.name
    ma

    codice:
    me.getAttribute("name")

  7. #7
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    277
    Scusa Andrea, ma è solo sbagliando che si impara!!!

    Comunque grazie ai tuoi consigli finalmente cel'ho fatta. Basta verificare l'id della <tr>, e cambiare lo script in:
    function SetActiveID_2(me){
    //alert (me);
    var id=(me.getAttribute("name").substr(12,14));
    //form.activeid.value=me.name;
    //elem = document.getElementById(ID).value;
    document.getElementById("nasc_new").value = me.getAttribute("name");

    Qui sotto lo script funzionante:









    <!doctype html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <HTML> <HEAD>
    <TITLE>
    SSP Version 0.0 - USER d - Anno: ND - Azienda ND </TITLE>


    <script language="Javascript">


    var pars="";

    function AIC(me){ //AddIDToidchanged
    me.style.background = "#0AFF00"; //background-color to green to let user know must use ajax
    var melength=me.name.length; // had to use length bec autoid can get larger than just 1 ,2,3,4, or 5 digits.
    var id=(me.name.substr(3,melength)); // will always be 3(f00) then autoid digits.
    if (id){
    var str=document.getElementById("idchanged").value; // if not sure how works then unhide the field on the form
    if (str==""){
    document.getElementById("idchanged").value=str + id;
    document.getElementById("nascosto").value=str + id;
    }else{
    if (!str.match(id)){
    document.getElementById("idchanged").value=str + "," + id;
    document.getElementById("nascosto").value=str + "," + id;
    }}
    // this added for ajax

    if (pars==""){
    pars=me.name + "=" + me.value;
    }else{
    pars=pars+"&"+me.name+"="+me.value;
    }}
    }


    function SetActiveID(me,form){
    //alert (me);
    var id=(me.name.substr(12,14));
    form.activeid.value=me.name;
    document.getElementById("nascosto").value=me.name;
    }
    function SetActiveID_2(me){
    //alert (me);
    var id=(me.getAttribute("name").substr(12,14));
    //form.activeid.value=me.name;
    //elem = document.getElementById(ID).value;
    document.getElementById("nasc_new").value = me.getAttribute("name");
    }
    function hasClass(obj) {
    var result = false;
    if (obj.getAttributeNode("class") != null) {
    result = obj.getAttributeNode("class").value;
    }
    return result;
    }






    </SCRIPT>
    </head>

    <form method=post action="./../ABILITAZIONE/save.php"><table id = "playlist" frame = box border = 1 cellspacing="0">
    <tr><td width="0%"></td>
    <td>Legal entity enabling </td>
    <td>Roles</td>
    <td>Password modification</td>
    <td>Other user details</td>
    <td>Login name</td>
    <td>First name</td>
    <td>Last name</td>
    <td>E-mail address</td>
    <td>Enabled</td>
    </tr>

    <tr id= "ID" onclick="SetActiveID_2(this);" onFocus="SetActiveID_2(this,this.id); " name ="062be1fc-ca11-102a-9eae-71cfbb3cf82a">
    <td width="0%"><input type="hidden" name="USER_ID[0]" value="062be1fc-ca11-102a-9eae-71cfbb3cf82a" disable = "disabled"></td>
    <td><input type="submit" name="LE_AB[0]" value = "Abilitazione aziende"></td>
    <td><input type="submit" name="ROLES_AB[0]" value = "Ruoli"></td>
    <td><input type="button" name = "Mod_pwd"
    onClick = window.open("./../PASSWORD/password.php?USER_ID=062be1fc-ca11-102a-9eae-71cfbb3cf82a","newwin","scrollbars=no,status=no,re sizable=yes,top=300,left=150,width=300,height=750" ) value = "Password modification " ></td>
    <td><input type="button" name = "Mod_dett"
    onClick = window.open("usr_details.php?USER_ID=062be1fc-ca11-102a-9eae-71cfbb3cf82a","newwin","scrollbars=no,status=no,re sizable=yes,top=300,left=150,width=300,height=750" ) value = "Other user details " ></td>
    <td>david </td>
    <td>d</td>
    <td>d</td>
    <td>cicici</td>
    <td><textarea rows="1" cols="1"class="boldblue"style="font:arial;"name="0 62be1fc-ca11-102a-9eae-71cfbb3cf82a"WRAP="virtual" onchange="AIC(this)" onclick="SetActiveID(this,this.form);"onFocus="Set ActiveID(this,this.form); "></textarea></td>
    <td> <input type= 'checkbox' name='FLG_ROLE_CODE_EDIT'></td></tr>
    </table>
    IDs Changed<input id="idchanged" name="idchanged" value="">

    Active Element's Name:<input name="activeid">




    </form>

    <form action="pippo.php" method="POST">
    <input type="text" id="nascosto" name="idchanged" value="">
    <input type="submit">
    </form>
    </form>

    <form action="pippo.php" method="POST">
    <input type="text" id="nasc_new" name="idchanged" value="">
    <input type="submit">
    </form>


    </body>
    </HTML>


    Grazie mille!

  8. #8
    prego

    ti ricordo ancora che il secondo argomento di questa chiamata

    SetActiveID_2(this, this.id);

    non lo usi mai. Cosa ti serve? Levalo

    Scusa Andrea, ma è solo sbagliando che si impara!!!
    Si', sono piu' che d'accordo. Ma ci vuole un minimo di strategia. Prendere script trovati in giro e sforbiciarli finche' non si adattano ai nostri scopi mi pare poco costruttivo. Una letta preliminare ai manuali non fa mai male ;-) Non e' una critica, solo un suggerimento


  9. #9
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,131
    Edit: Sbagliato :berto:
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  10. #10
    Utente di HTML.it
    Registrato dal
    Apr 2007
    Messaggi
    277
    Mmm.. scusa ma non ho capito!

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 © 2024 vBulletin Solutions, Inc. All rights reserved.