i am trying a dynamic max power and "x" value input.everything is fine the problem is i can not replace the (x^something) dynamically with replace() method.
HTML Code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
#gap{
    width:200px;
    height:50px;
    border:1px solid black;
}
thiss{
    width:200px;
    height:50px;
}
</style>
</head>

<body>
<div id="gap"></div>
<p id="thiss"></p>
<input type="button" value="replace this" onClick="change();">
<script>
function change(){
    var m=document.getElementById("gap");
    var n=document.getElementById("thiss");
    var t=document.getElementById("thiss").innerHTML;
    var power=prompt("input highest power of x:");
    var i;
    var arr=new Array();
    for( i=power;i>=0;i--){
        arr[i]=prompt("coeff of x^"+i);
    }
    i=power;
    for(i=power;i>=0;i--){
        if(arr[i]>0 && i==power){
            n.innerHTML += arr[i]+"*x^"+i;
        }
        else if(arr[i]<0 && i==power){
            n.innerHTML += arr[i]+"*x^"+i;
        }
        else if(arr[i]>0 && i!=power){
    n.innerHTML += "+"+arr[i]+"*x^"+i;
        }
        else if(arr[i]<0){
            n.innerHTML += arr[i]+"*x^"+i;
        }else if(arr[i]==0){
            n.innerHTML += "";
        }
            
    }
    var x_val=prompt("solve with x =");
i=power;
for(i=power;i>=0;i--){
    m.innerHTML=eval(t.replace(/x\^i/,"Math.pow(x_val,i)"));
}
    
}


</script>

</body>
</html>
mainly problem is here.i know this is garbage .but how can it be fixed.how can i replace using variable
HTML Code:
for(i=power;i>=0;i--){
	m.innerHTML=eval(t.replace(/x\^i/,"Math.pow(x_val,i)"));
}