Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    Problema cambio sfondo <table> da una <select>

    Salve, ho problema molto piccolo ma come si sa i piccoli problemi di programmazione non si vedono mai. ;-). Ecco il codice (ho eliminato molte righe per arrivare all'essenziale), qualcuno riuscirebbe a dirmi dove sbaglio? Il risultato è che non cambia lo sfondo della tabella.
    Premetto che ho già cercato molti siti (anche w3schools) ma niente...grazie

    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
    <% @
    LANGUAGE="JScript" %>
    <
    html>
        <
    head>
            <
    meta http-equiv="Content-type" content="text/html;charset=UTF-8">
        </
    head>
    <
    body>
        <%
        var 
    i;
        
    Response.write("<form name='Form' method='post' action='sendCookie.asp'>");
            
    Response.write("<table id='tableColor'>");
                for(
    i=0;i<2;i++)
                    
    Response.write("<tr><td><input type='text' name='name"+i+"' value=''></td></tr>");
                
    Response.write("<select name='deafultColor'");
                
    Response.write("onchange='document.getElementById('tableColor').bgcolor=value'>");
                    
    Response.write("<option value='red'>red</option>");
                    
    Response.write("<option value='white' selected='selected'>white</option>");
                    
    Response.write("<option value='blue'>blue</option>");
                
    Response.write("</select>");
            
    Response.write("</table>");
        %>
    </
    body>
    </
    html
    My site: www.andreaciani.com

  2. #2
    codice:
    <%
    color = request.queryString("color")
    if len(color) = 0 then color = "white"
    %>
    <table bgcolor="<%=color%>">
      <tr>
        <td>
          <form>
            <select name="color" onchange="document.location.href='?color='+this.value;">
              <option value="white"<% if color = "white" then %> selected="selected"<% end if %>>WHITE</option>
              <option value="green"<% if color = "green" then %> selected="selected"<% end if %>>GREEN</option>
              <option value="yellow"<% if color = "yellow" then %> selected="selected"<% end if %>>YELLOW</option>
            </select>
          </form>
        </td>
      <tr>
    </table>

  3. #3
    Dovresti usare :

    codice:
    document.getElementById('tableColor').style.backgroundColor = options[selectedIndex].value;
    .

    Inoltre, occhio, la select è dentro la tabella ma fuori dalle celle.

    Ciau!
    - Dean

  4. #4
    -Per domenix:
    Ho provato la tua soluzione ma non funziona tra l'altro credo tu abbia usato VBscript. Non ho specificato l'utilizzo del Javascript ma cmq la soluzione che hai postato l'ho trovata originale grazie.

    -Per Atari:
    Grazie per la questione della select cmq ho provato anche la tua soluzione...non capisco solo come usare quel...options[selectedIndex].value;
    nel senso che ho provato in tutti modi ma...nothing (ho studiato cmq il style.background su w3schools).
    Ho provato con:
    Response.write("onchange='document.getElementById( 'tableColor').style.backgroundColor =document.Form.defalultColor.value'>");

    Nuovo codice modificato:
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
    <% @
    LANGUAGE="JScript" %>
    <
    html>
        <
    head>
            <
    meta http-equiv="Content-type" content="text/html;charset=UTF-8">
        </
    head>
    <
    body>
        <%
        var 
    i;
        
    Response.write("<form name='Form' method='post' action='sendCookie.asp'>");
            
    Response.write("<table id='tableColor'>");
                for(
    i=0;i<2;i++)
                {
                    
    Response.write("<tr><td><input type='text' name='name"+i+"' value=''></td></tr>");
                }
                
    Response.write("<tr><td><select name='deafultColor'");
                var 
    orange="red";        Response.write("onchange='document.getElementById('tableColor').style.backgroundColor =document.Form.defalultColor.value'>");
                    
    Response.write("<option value='red'>red</option>");
                    
    Response.write("<option value='white' selected='selected'>white</option>");
                    
    Response.write("<option value='blue'>blue</option>");
                
    Response.write("</select></td></tr>");
            
    Response.write("</table>");
        %>
    </
    body>
    </
    html
    My site: www.andreaciani.com

  5. #5
    si sovrappongono gli apici del javascript con quelli dell'attributo html :
    codice:
    onchange=""document.getElementById('tableColor').style.backgroundColor =  options[selectedIndex].value""
    Ciau!
    - Dean

  6. #6
    Scusa Atari, mi son spiegato male , intendevo come si usa quel options[selectedIndex].value

    Nel mio caso dovrei scrivere deafultColor["qualcosa"].value?

    Grazie
    My site: www.andreaciani.com

  7. #7
    non ti piace così come è?
    Riferimento: http://www.aptana.com/reference/html/api/Select.html

    Ciau!
    - Dean

  8. #8
    Ok perfetto, eheh ora ho capito cmq adesso cercherò di usare queste info ed altre per correggere il mio errore, posterò la soluzione funzionante.

    Grazie a tutti!
    My site: www.andreaciani.com

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.