getElementById fejl ved brug af mouse
Hey EIIS5.0/ASP/javascript/IE
Kort fortalt, så er her et script er giver en bruger mulighed for at sammensætte sin SQL ud fra at flytte nogen felter rundt med musen. Koden skal lave en SQL ud fra nedenstående kode. I forbindelse med at jeg skal flytte en DIV til venstre får fejlen:
Fejl: document.getElementById(...)' er null eller ikke et objekt.
i linje 349.
-> Vis kilde og linje 349 giver:
document.getElementById('addme2').innerHTML = sText + '<br/>' + aAll.length
What to do?
Koden er:
<!--#include virtual="/fsnskp/RT-SRS/conn.asp" -->
<%
OverskriftAll2 = Array("","Hale nr","Tildelt","Block nr","MLU","Flyvetimer","SI timer","Plan dato","Ind dato","Ud dato","Lokation","Eftersyn","ETIC","Egress","Våben","Dinghy","Stel","Vbem","STA1","STA2","STA3","STA4","STA5","STA6","STA7","STA8","STA9","CF","Ammo","Gun S","Shelter","bem","Rest","NDI","Lox","45","30","Batt","LAU","ALQ","mode","ETU")
arrIndhold = Array("","MOC_stelnr","MOC_enhed","MOC_blocknr","MOC_MLU","MOC_minutter","MOC_SI_min","S_plan_dato","S_ind_dato","S_ud_dato","S_lokation","S_bem","S_FCF","S_V_NT_Egress","S_V_NT_Vaaben","S_V_NT_Dinghy","S_V_NT_Stel","S_V_NT_bem","S_V_STA1","S_V_STA2","S_V_STA3","S_V_STA4","S_V_STA5","S_V_STA6","S_V_STA7","S_V_STA8","S_V_STA9","S_V_CF","S_V_Gun_A","S_V_Gun_S","S_Shelter","S_V_bem","S_V_Rest","S_V_NDI","S_V_Lox","S_V_45","S_V_30","S_V_Batt","S_V_LAU","S_V_ALQ","S_V_mode","S_V_ETU")
strSQL = "select top 10 * from fly_status"
set rsCustom = Server.CreateObject("ADODB.RecordSet")
rsCustom.Open strSQL, conn
' Session("hvem") = 120419
strSQL = "select * from brugere where b_medarbejdernr = '" & Session("hvem") & "'"
set rsUser = Server.CreateObject("ADODB.RecordSet")
rsUser.Open strSQL, conn,3,3
If not rsUser.EOF Then
strIndhold = rsUser("B_Custom")
If strIndhold = "" then strIndhold = "1;"
End If
bClose = false
arrCustom = Split(strIndhold,";")
sJavaArray = Left(strIndhold,len(strIndhold) - 1)
sJavaArray = Replace(sJavaArray,";",""",""")
sJavaArray = """" & sJavaArray & """"
Dim arrFinal()
ReDim arrFinal(ubound(arrCustom))
For i = 0 to ubound(arrCustom) - 1
arrFinal(i) = arrIndhold(CInt(arrCustom(i)))
db = db & "," & arrIndhold(CInt(arrCustom(i)))
Next
If Cstr(Request.QueryString("submit")) = "true" Then
db = ""
strIndhold = ""
strIndhold = Request.QueryString("Selected")
arrCustom = Split(strIndhold,";")
ReDim arrFinal(ubound(arrCustom))
For i = 0 to ubound(arrCustom) - 1
arrFinal(i) = arrIndhold(CInt(arrCustom(i)))
db = db & "," & arrIndhold(CInt(arrCustom(i)))
Next
rsUser("B_Custom") = strIndhold
rsUser.Update
bClose = True
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<style>
.addMe {
position:absolute;
height:60px;
width:30px;
border:1 solid black;
}
.lodret {
writing-mode:tb-rl;
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=0);
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: bold;
height: 110px;
border: 2px outset #CCFFFF;
background-color: #0099CC;
}
.pointer {
cursor:pointer;
background-color:#CCCCCC;
text-align:center;
width:30px;
}
</style>
<script language="javascript" type="text/javascript">
<!--
var a, strPosLeft, strPosTop, difLeft, difTop, sItem;
var w1 = 't'
var w2 = 's'
//var itemCount = 22;
//var aCount = new Array("7","17","6","20","22","23","24","25","26","27","28","12","3","4","8","1","2","9","10","11","5","13");
var itemCount = <%=ubound(arrCustom)%>;
var aCount = new Array(<%=sJavaArray%>);
function windowMove(x,y) {
document.getElementById(sItem).style.posLeft = strPosLeft - x;
document.getElementById(sItem).style.posTop = strPosTop - y;
}
function doStart(input) {
sItem = input
a = true
difPosLeft = (strPosLeft - document.getElementById(sItem).style.posLeft);
difPosTop = (strPosTop - document.getElementById(sItem).style.posTop );
}
function doStop() {
a = false;
document.getElementById(sItem).style.posTop = 5;
var iItemX = 0;
iItemX = document.getElementById(sItem).style.posLeft;
var iMove = false;
var iX = 0;
var thisItem = '';
thisItem = sItem;
var iSelect = 0;
for(var i=0; i<aCount.length; i++) {
if(aCount[i] == sItem) { iSelect = i; }
}
var iX = 1;
var aAll = new Array(itemCount)
var sText = '';
for(var i=0; i<aCount.length; i++) {
if(i != iSelect) {
iTempX = (iItemX - document.getElementById(aCount[i]).style.posLeft)
if(iMove != true) {
if((iTempX < 31)) {
if((iTempX > 13)) {
aAll[i] = aCount[i]
//alert('Function 1\n' + aCount[i] + ' forbliver på plads ' + i);
sText = sText + 'Function 1: ' + aCount[i] + ' forbliver på plads ' + i + '<br/>';
iMove = false;
}
else {
iMove = true;
sText = sText + 'Function 2: ' + aCount[iSelect] + ' får plads ' + i + ' og ' + aCount[i] + ' får plads ' + (parseFloat(i) + 1) + '<br/>'
//alert('Function 2\n' + aCount[iSelect] + ' får plads ' + i + ' og ' + aCount[i] + ' får plads ' + (parseFloat(i) + 1));
aAll[i] = aCount[iSelect];
aAll[(parseFloat(i) + 1)] = aCount[i];
}
}
else {
//alert('Function 3\n' + aCount[i] + ' forbliver på plads ' + i);
sText = sText + 'Function 3: ' + aCount[i] + ' forbliver på plads ' + i + '<br/>';
aAll[i] = aCount[i];
}
}
else {
sText = sText + 'Function 4: ' + aCount[i] + ' får plads ' + (parseFloat(i) + iX) + '<br/>';
//alert('Function 4\n' + aCount[i] + ' får plads ' + (parseFloat(i) + 1));
aAll[(parseFloat(i) + iX)] = aCount[i];
}
}
else {
iX = 0;
//alert('5\n' + i)
}
}
//for(i=0; i<aAll.length; i++) {
// sText = sText + ',' + aAll[i]
//}
document.getElementById('addme2').innerHTML = sText + '<br/>' + aAll.length
var k = 0;
for(i=0; i<aAll.length; i++) {
//alert(aAll[i]);
//if(!isNaN(aAll[i])) {
document.getElementById(aAll[i]).style.posLeft = (i * 31) + 5;
document.getElementById(aAll[i]).style.posTop = 5;
// aCount[k] = aAll[i];
// k++;
//}
}
aCount = aAll;
}
function mouseTracker()
{
strPosLeft = event.x;
strPosTop = event.y;
if (a == true) { windowMove(difPosLeft,difPosTop,sItem); }
}
function addMe(value,id,sName,title) {
//alert(sName + '\n' + document.form1.db.value + '\n' + document.form1.db.value.indexOf(sName));
if(document.form1.db.value.indexOf(sName) < 0) {
sInnerHTML = '<div class="addme" id="' + id +'" Style="Top:5px;Left:' + (((itemCount) * 31) + 5) + ';height:120px;" onMouseDown="doStart(this.id);" onMouseUp="doStop();"><input type="checkbox" id="' + id + '" name="' + id + '" checked /> ' + title + '</div>';
if (document.getElementById('addme').innerHTML == '') {
document.getElementById('addme').innerHTML = sInnerHTML;
}
else {
document.getElementById('addme').innerHTML = document.getElementById('addme').innerHTML + sInnerHTML;
}
document.form1.db.value = document.form1.db.value + ',' + sName;
itemCount++;
sText = ''
aCount[aCount.length] = id;
}
}
function doSubmit() {
var sText = '';
for(var i=0;i<document.form1.length;i++) {
if(document.form1[i].name != 'values' && document.form1[i].name != 'submit' && document.form1.name != 'db') {
if(document.form1[i].checked == true) {
sText = sText + document.form1[i].name + ';';
}
}
}
document.location.href=('default.asp?mode=tavlevalg&submit=true&selected=' + sText);
}
function changeIndex() {
var sText = '';
for(var i=0;i<aCount.length;i++) {
document.getElementById(aCount[i]).innerHTML = aCount[i];
sText = sText + ',' + aCount[i];
}
document.getElementById('addme2').innerHTML = sText + '<br/>' + aCount.length;
}
function dm() {
return false;
}
function dd(e) {
if(e.which==3) {
return dm();
}
}
function cm(){
hg=event.button;
if(hg==2||hg==3) dm();
}
function da() {
{
return false;
}
}
d=document;
vc=d.all;
qb=d.getElementById;
if(vc){
if(qb){
d.onselectstart=dm
}
}
document.onmousemove=mouseTracker;
//-->
</script>
</head>
<body <%if bClose then%>onload="window.opener.location.reload(true);window.close();"<%end if%>>
<form name="form1" id="form1" action="" method="post">
<input type="hidden" name="values" id="values" />
<input type="hidden" name="db" id="db" value="<%=db%>" />
<% Dim tal
tal = 0
For i = 0 to ubound(arrCustom) - 1
tal = tal + 1
j = arrCustom(i)
%>
<div id="t<%=j%>" Style="Top:5px;Left:<%=((i + 1) * 31) - 26%>px;height:120px;" class="addme" onMouseDown="doStart(this.id);" onMouseUp="doStop();">
<table cellpadding="0" cellspacing="0" height="120px">
<tr>
<td class="pointer" onMouseDown="doStart(<%=j%>);" onMouseUp="doStop();">-</td>
</tr>
<tr>
<td nowrap class="lodret" height="100px">
<input type="checkbox" id="<%=j%>" name="Checkbox<%=tal%>" style="height:20px " checked/>
<%=OverskriftAll2(j)%>
</td>
</tr>
</table>
</div>
<%
Next
%>
<div id="addme"></div>
<br/><br/>
<br/><br/><br/><br/><br/>
<input type="button" value="submit" onclick="doSubmit();" ID="Button1" NAME="Button1"/>
</form>
<iframe src="add.asp" width="700px" height="150px" scrolling="auto" frameborder="0"></iframe>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:2000;"></div>
