Questo script funziona alla grande,fuori dal tag table,ma se metto il form dentro la tag table non manda il request alla pagina php....Codice HTML:<script type="text/javascript" language="javascript"> var http_request = false; function makeRequest(getvar) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { //http_request.overrideMimeType('text/xml'); // See note below about this line } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } http_request.onreadystatechange = function(){ scrivi(getvar); } http_request.open('POST', 'admin/mode_blocks_save.php', true); http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); postvar="campo="+getvar+"&value="+eval("document.forms.dinamicform."+getvar+".value")+"&idblck=12"; http_request.send(postvar); } function scrivi(getvar) { if (http_request.readyState == 4) { if (http_request.status == 200) { document.getElementById(getvar).innerHTML = "<a href=\"javascript:void(null);\" onclick=\"change(this,'"+getvar+"')\">"+eval("document.forms.dinamicform."+getvar+".value")+"</a>"; document.getElementById("result").innerHTML = http_request.responseText; } else { alert('There was a problem with the request.'); } } } function change(link,textname){ //link.innerText e link.text sono stessa cosa, c'è differenza tra ie e firefox if(link.innerText){testovecchio=link.innerText}else{testovecchio=link.text} //riscrivo il contenuto del div document.getElementById(textname).innerHTML="<textarea name='"+textname+"' value='"+testovecchio+"'>"+testovecchio+"</textarea> <input type='button' value='ok' onclick=\"makeRequest(\'"+textname+"\')\">"; } </script> <table> <form name="dinamicform"> <div id="content"><a href="javascript:void(null);" onclick="change(this,'content')">Cambia Contenuto</a></div> </form> <br/> <br/> <div id="result">Nuovo contenuto</div> </table>
Come fare?