Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Valore radio undefined

  1. #1

    Valore radio undefined

    Ciao a tutti ho una pagina php che mi preleva dati da un db e compila una tabella che si trova all'interno di un form, una cella di ogni riga contiene un radio a cui assegno un valore univoco. Sull'onclick della riga della tabella chiamo uno script javascript...il problema è che se io ho una sola riga l'array che contiene tutti i radio mi ritorna undefined se invece ho due o più radio funziona correttamente...che sbaglio?

  2. #2
    ciao, è un po' difficile fare supposizioni senza leggere una riga di codice: potresti incollare qui cosa viene prodotto nel caso si abbia una sola riga nella tua tabella?

    saluti

  3. #3
    Questo è il codice php
    Codice PHP:
    <form name="myform" method="post">
                <?php
                $query 
    "SELECT * FROM Clienti ORDER BY Denominazione ASC LIMIT $first$record;";
                
    $result mysql_query($query$db->connect()) or die(mysql_error());
                
    $query_rec mysql_num_rows($result);
                
    $i 0;
                
    $value 0;            
                while(
    $row mysql_fetch_array($result))
                {
                    if (isset(
    $_REQUEST['idc']) && $row['Id'] == $_REQUEST['idc'])
                        {
                            
    $css "highlightedRow";
                            if (
    $i == 0)
                                {
                                    
    $i++;
                                }
                            else
                                {
                                    
    $i 0;
                                }
                        }                
                    elseif (
    $i == 0)
                        {
                            
    $css "table_row1";
                            
    $i++;
                        }
                    else
                        {
                            
    $css "table_row";
                            
    $i 0;
                        }
            
    ?>
                <tr onClick="highlight(this, '<?php echo $css?>', '<?php echo $value?>', '<?php echo $_REQUEST[page]; ?>', '<?php echo $_REQUEST[user]; ?>', '<?php echo $_REQUEST[id]; ?>', '<?php echo $_REQUEST[pag]; ?>');" class="<?php echo $css?>" id="<?php echo $value?>">
                    <th id="th">
                        <?php echo $row['Id']; ?>
                        <input type="radio" name="idc" value="<?php echo $row['Id']; ?>" style="display:none;"; <?php if ($css == "highlightedRow") { echo "checked"; } ?> />                                    
                    </th>
                    <th id="th">
                        <?php echo $row['Denominazione']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Indirizzo']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Cap']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Citta']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Provincia']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Codice_fiscale']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Piva']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Telefono']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Fax']; ?>
                    </th>
                    <th id="th">
                        <?php echo $row['Cellulare']; ?>
                    </th>
                </tr>
                <?php
                $value
    ++;
                }
            
    ?>
                        <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" />
                        <input type="hidden" name="user" value="<?php echo $_REQUEST['user']; ?>" />
                        <input type="hidden" name="id" value="<?php echo $_REQUEST['id']; ?>" />            
            </form>
    e questo è il codice javascript
    codice:
    var td1 = null;
    
    function highlight(el, clas, value, page, user, id, pag) {
    	document.write(document.myform.idc[value].value);
    	/*if (document.myform.idc.lenght == undefined)
    		{
    			value = 0;
    		}*/
    	//document.write(value);	
    	if (document.myform.idc[value].checked == true)
    		{
    			var url = new String(document.location);
    			url = url.replace("idc="+document.myform.idc[value].value+"&", "");
    			location.href = url;
    			return;
    		}		
    	if (clas = "table_row")
    		{
    			clas = "table_row1";
    		}
    	else if(clas = "table_row1")
    		{
    			clas = "table_row";
    		}
    	if (td1)
    	{
    		td1.className = clas;
    	}	
    	el.className = "highlightedRow";
    	td1 = el;
    	document.myform.idc[value].checked = true;
    	if (pag != "")
    		{
    			document.myform.action = "main.php?idc="+document.myform.idc[value].value+"&page="+page+"&user="+user+"&id="+id+"&pag="+pag;
    		}
    	else
    		{
    			document.myform.action = "main.php?idc="+document.myform.idc[value].value+"&page="+page+"&user="+user+"&id="+id;
    		}	
    	document.myform.submit();
    }

  4. #4
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Errori riscontrati l'id deve essere univoco <th id="th"> tu ne hai 11 nel documento.
    if (clas = "table_row") se è un controllo gli uguale (=) devo essere due ==
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  5. #5
    Errori riscontrati l'id deve essere univoco <th id="th"> tu ne hai 11 nel documento. if (clas = "table_row") se è un controllo gli uguale (=) devo essere due ==
    hai ragione per quanto riguarda l'id è un errore html che non influisce col mio script per il confronto svista mia...cmq ho risolto infatti nel mio script javascript trattavo sempre il valore del radio come un array di elementi ma ho scoperto che se c'è un solo elemento non viene trattato come un'array ma bisogna trattarlo come un'elemento semplice...in sostanza lo script è cambiato così:
    codice:
    var td1 = null;
    var radio = null;
    
    function highlight(el, clas, value, page, user, id, pag) {
    	//document.write(value);
    	if (document.myform.idc.length == undefined)
    		{
    			radio = document.myform.idc;
    			//document.write("undefined");
    		}
    	else
    		{
    			radio = document.myform.idc[value];
    			//document.write("valore");
    		}
    	//document.write(radio.value);	
    	if (radio.checked == true)
    		{
    			var url = new String(document.location);
    			url = url.replace("idc="+radio.value+"&", "");
    			location.href = url;
    			return;
    		}		
    	if (clas == "table_row")
    		{
    			clas = "table_row1";
    		}
    	else if(clas == "table_row1")
    		{
    			clas = "table_row";
    		}
    	if (td1)
    	{
    		td1.className = clas;
    	}	
    	el.className = "highlightedRow";
    	td1 = el;
    	radio.checked = true;
    	if (pag != "")
    		{
    			document.myform.action = "main.php?idc="+radio.value+"&page="+page+"&user="+user+"&id="+id+"&pag="+pag;
    		}
    	else
    		{
    			document.myform.action = "main.php?idc="+radio.value+"&page="+page+"&user="+user+"&id="+id;
    		}	
    	document.myform.submit();
    }

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.