Note that there are some explanatory texts on larger screens.

plurals
  1. POgetElementById breaks script
    primarykey
    data
    text
    <p>I'm working on a little project, but I'm stuck and don't know what I'm doing wrong.<br> I use Ajax to call a php-script that updates a MYSQL-row.</p> <p>The javascript:</p> <pre><code>function savecust() { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("custdetails").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","./ajax/savecust.php?id=" + document.getElementById('id').value,true); //More arguments should still be passed. xmlhttp.send(); } </code></pre> <p>If I remove the <code>document.getElementById('id').value</code> the script works and does what is is supposed to do. (I get the response from the PHP, obviously</p> <p>I load the script in the head of the page along with some other scripts:</p> <pre><code>&lt;script src="js/custedit.js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>This is how I call the script:</p> <pre><code>&lt;input type='button' onclick='savecust()' value='Save' /&gt; </code></pre> <p>Any help would be greatly appreciated ;-).</p> <p>Thanks!</p> <h2>EDIT</h2> <ul> <li>The div where the content should go, exists.</li> <li>The PHP-scripts returns an error for now (because it doesn't get all the required parameters)</li> <li>The content (and textfield with id: 'id') is loaded by another script. Is this a problem? If you look at the source in a browser the textfields are not there. They are however visible in the browser. </li> </ul> <h2>EDIT 2</h2> <p>So, I ran this test on top of my script:</p> <pre><code>var thisid = 'id';//should get info from &lt;input type='text' name='id' /&gt; var T = document.getElementById(thisid); if (T) { alert("element exists" + T.value); } else { alert("nothing to be found"); } </code></pre> <p>It is indeed unable to find the element. This pointed me in the right direction.<br> <code>&lt;input type='text' name='id' /&gt;</code>is inserted by another Ajax-script. So I think the second script is unable to find it.</p> <p>How do I solve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload