0

I will try in a new more specific attempt. I’m trying to get the value for my <span id=”$var”>BadText</span> from a variable. Passing the idFull to the function works fine by first writing the value to a JS variable. But in the span area doesn’t work. I always get “document.getElementById(...) is null“. May you have a solution there? I already crossed my Mind but I found no clue. For me it looks like a problem with the scope of variables or the order of execution.

function transferFader(value,id)
{
    if (window.XMLHttpRequest)
    {
         // AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera
         xmlhttp=new XMLHttpRequest();
     }
     else
     {
          // AJAX mit IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     xmlhttp.onreadystatechange=function()
    {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
document.getElementById("result"+id).innerHTML=xmlhttp.responseText;
      }
    }
xmlhttp.open("GET","backEnd.php?v="+value+"&id="+id,true);
     xmlhttp.send();
    return;
} 
<?
  function slider(){
    echo('
      var idFull = "123";
      var idFullResult = "result123";
      <form oninput="transferFader(auswertung.value,idFull)">
        <input type="range" name="auswertung" min="0" max= "63" value="30"    orient="vertical">
        <br>
        <span id=idFullResult>n.a.</Span>
      </form>
    ');
  }
  slider();
?>
geerkins
  • 11
  • 3

2 Answers2

0

$idFull and $idFullResult are never set in PHP. Also the id of your span is hardcoded to idFullResult. I find this code hard to read, but I think you meant to do this:

echo 'var idFull = "' . $id . '"';
echo '<span id="result' . $id . '">n.a.</span>';

Mixing PHP, JS, and HTML all in one place is generally bad practice for a number of reasons. This is one example of the confusion it can cause.

Matt S
  • 14,976
  • 6
  • 57
  • 76
0
 echo('
      var idFull = "123";
      var idFullResult = "result123";
      <form oninput="transferFader(auswertung.value,idFull)">
        <input type="range" name="auswertung" min="0" max= "63" value="30"    orient="vertical">
        <br>
        <span id=idFullResult>n.a.</Span>
      </form>
    ');

Your problem lies within this span, <span id=idFullResult>n.a.</Span>

HTML will not match the closing tag, it should be </span>. Also, you are trying to make us of js string substitution inside PHP with the span's id tag. idFullResult will not expand as expected.

Mark Carpenter Jr
  • 812
  • 1
  • 16
  • 32
  • thanks. I just noticed the uper case. chnaged it. But the result dosn't change. May you have an Idea how to fix it? – geerkins Jan 11 '18 at 16:32