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

    [js] non funziona su IE (aggiungi campi form)

    ciao a tutti,
    ho trovato nella sezione script utili come creare dinamicamente dei campi a un form, ho provato a riadattarlo ai miei bisogni ma purtroppo non funziona sotto IE (funziona invece con Firefox e Safari)


    vi posto il codice, se non capite qualunque cosa posso dare ogni chiarimento.

    grazie a tutti
    danno

    codice:
    <html>
    <head>
    <script language="javascript" type="text/javascript">
    var restaurants = 2;
    
    function more_rest()
    {	var main_tr=document.createElement("TR");
    	var main_td=document.createElement("TD");
    	var new_table=document.createElement("TABLE");
    	var labels=new Array("Restaurant #","Name","Location","Type of the Food","Meals Served","Rating","Dress Code","Serving Times","Breakfast","Lunch","Dinner","Brunch","Description");
    	
    	//in un ciclo
    	for(i=0;i<13;i++)
    	{	var new_tr=document.createElement("TR");
    		var new_td1=document.createElement("TD");
    		if(i>7 && i<12)
    			new_td1.align = 'right';
    		var new_td2=document.createElement("TD");
    		if(i==0)
    			var new_label=document.createTextNode(labels[i]+restaurants+':');
    		else
    			var new_label=document.createTextNode(labels[i]+':');
    		var new_field=document.createElement("INPUT");
    		new_field.type = 'text';
    		
    		//appende i figli al padre
    		new_td1.appendChild(new_label);
    		new_td2.appendChild(new_field);
    		new_tr.appendChild(new_td1);
    		new_tr.appendChild(new_td2);
    		new_table.appendChild(new_tr);
    	}
    	main_td.appendChild(new_table);
    	main_tr.appendChild(main_td);
    	document.getElementById('rest_table').getElementsByTagName('TBODY')[0].appendChild(main_tr);
    	
    	restaurants++;
    }
    </script>
    </head>
    
    <body>
    <table id="rest_table">
    	<tr>
    		<td>
    			<table>
    				<tr><td>Restaurant #1</td><td><input type="text"></td></tr>
    				<tr><td>Name:</td><td><input type="text"></td></tr>
    				<tr><td>Location</td><td><input type="text"></td></tr>
    				<tr><td>Type of the Food</td><td><input type="text"></td></tr>
    				<tr><td>Meals Served</td><td><input type="text"></td></tr>
    				<tr><td>Rating:</td><td><input type="text"></td></tr>
    				<tr><td>Dress Code:</td><td><input type="text"></td></tr>
    				<tr><td>Serving Times:</td><td><input type="text"></td></tr>
    				<tr><td align="right">Breakfast:</td><td><input type="text"></td></tr>
    				<tr><td align="right">Lunch:</td><td><input type="text"></td></tr>
    				<tr><td align="right">Dinner:</td><td><input type="text"></td></tr>
    				<tr><td align="right">Brunch:</td><td><input type="text"></td></tr>
    				<tr><td>Description:</td><td><input type="text"></td></tr>
    			</table>
    		</td>
    	</tr>
    </table>
    
    <input type="button" value="more restaurants >>" onClick="javascript:more_rest()">
    
    
    </body>

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Potresti fare anche cosi

    codice:
    <html>
    <head>
    <script language="javascript" type="text/javascript">
    var restaurants = 0;
    function more_rest() {
     restaurants++;
    
     aDiv = document.getElementById('template');
     html = aDiv.innerHTML.replace(/xxxxx/ig,restaurants);
     
     document.getElementById('pippo').innerHTML += html;
    } // function _more_rest()
    </script>
    
    </head>
    
    <body onload="more_rest()">
    
    <div id="template" style="display:none">
    <table>
    <tr>
     <td>
      <table>
       <tr><td>Restaurant #xxxxx</td><td><input type="text" name="rest[xxxxx]"></td></tr>
       <tr><td>Name:</td><td><input type="text" name="nam[xxxxx]"></td></tr>
       <tr><td>Location</td><td><input type="text" name="loc[xxxxx]"></td></tr>
       <tr><td>Type of the Food</td><td><input type="text" name="food[xxxxx]"></td></tr>
       <tr><td>Meals Served</td><td><input type="text"  name="meal[xxxxx]"></td></tr>
       <tr><td>Rating:</td><td><input type="text"  name="rat[xxxxx]"></td></tr>
       <tr><td>Dress Code:</td><td><input type="text"  name="dress[xxxxx]"></td></tr>
       <tr><td>Serving Times:</td><td><input type="text"  name="serv[xxxxx]"></td></tr>
       <tr><td align="right">Breakfast:</td><td><input type="text"  name="brk[xxxxx]"></td></tr>
       <tr><td align="right">Lunch:</td><td><input type="text" name="lun[xxxxx]"></td></tr>
       <tr><td align="right">Dinner:</td><td><input type="text" name="din[xxxxx]"></td></tr>
       <tr><td align="right">Brunch:</td><td><input type="text" name="bru[xxxxx]"></td></tr>
       <tr><td>Description:</td><td><input type="text" name="desc[xxxxx]"></td></tr>
      </table>
     </td>
    </tr>
    </table>
    </div>
    
    <div id="pippo">
    </div>
    
    <input type="button" value="more restaurants >>" onClick="javascript:more_rest()">
    
    
    </body>
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

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.