Note that there are some explanatory texts on larger screens.

plurals
  1. POEnabling/Disabling a button after database query
    primarykey
    data
    text
    <p>I want to disable or enable a button, depending on the result of a database-query. But I don't know how. From an example, I managed to show a text (id="error", depending on the result of the query, but enabling the button (id="generate") does not work. </p> <p>This is my JavaScript:</p> <pre><code>function checkSender(str) { if(str == "") { str=document.getElementById("senderinput").value; } str=str.toUpperCase(); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById("error").innerHTML=xmlhttp.responseText; if(xmlhttp.responseText == "Einsender existiert nicht.") { document.getElementById("generate").disabled = true; } else { document.getElementById("generate").disabled = false; } } } xmlhttp.open("GET","checkSender.php?s="+str,true); xmlhttp.send(); } </code></pre> <p>The response from checkSender.php is either "Einsender existiert nicht." or an empty string.</p> <p>Any suggestions?</p> <p><strong>EDIT</strong>:</p> <p>The PHP-Code:</p> <pre><code>&lt;?php require 'classes/DBHandler.php'; $DBHandler = new class_DBHandler(); $s = $_GET['s']; $query="&lt;Statement with $s as parameter&gt;"; $Data = $DBHandler-&gt;GetData($query); if(intval($Data[0]['COUNT']) &gt;= 1) { echo ""; } else { echo "Einsender existiert nicht."; } ?&gt; </code></pre> <p>The HTML-Code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt; &lt;link rel="stylesheet" type="text/css" href="style.css"&gt; &lt;script src="inc/checkSender.js"&gt;&lt;/script&gt; &lt;title&gt;MarPro&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="main"&gt; &lt;div class="debug" id="ana"&gt; &lt;/div&gt; &lt;div class="headline"&gt; &lt;h1&gt;MarPro&lt;/h1&gt; &lt;/div&gt; &lt;div class="result"&gt; &lt;div class="menu"&gt; &lt;form action="" method="post" name="senderform"&gt; &lt;p&gt;Einsender: &lt;input type="text" name="sender" onkeyup="checkSender(this.value)"&gt;&lt;/p&gt; &lt;p id="error"&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" name="generate" value="Generieren" id="generate" disabled&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thanks in advance!</p> <p>Marco Frost</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.
    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