Im trying to make a program for analyzing language. Im using a model that is well known for analyzing my language.
The problem works so I have a sentence that the surfer needs to put into boxes(sorted in verbal, subject, etc.).
I made the program so you highligt a box, byt clicking it- and afther that click each word in the sentence to put it in one of the boxes.
Howerver I need the words to keep their respective places in the boxes.
For instance- if the sentence is “Help me please” and if I choose to put all 3 in box#3- BUT I want to click “please” 1st- then “Help” and last “me”- they should all end as “Help me please” in the box. This should work with large sentences as well of course.
Another example if there is 10 words- I(the user) want to put 3 in box 1, 4 words in box 2 and 3 in box 3- no matter what order they are clicked- they should keep the same order as in the sentence before it was sorted.
Ive tried 2-dimensionel arrays- but I just can get it working:-(
This is the program(small scale- when im done its gona be about 8 boxes and it has to work with all size sentences, I know its a bit of a mess- but please focus on my problem:-P):
<HTML>
<HEAD>
<TITLE>Online løsning af sætningsskema</TITLE>
<style type=”text/css” media=”screen”>
.hlt {
background-color: #999;
color: black;
}
</style>
<script type=”text/javascript”>
////////
function delete_cookie ( cookie_name )
{
var cookie_date = new Date ( ); // current date & time
cookie_date.setTime ( cookie_date.getTime() – 1 );
document.cookie = cookie_name += “=; expires=” + cookie_date.toGMTString();
}
delete_cookie ( “basket” );
delete_cookie ( “empty” );
document.cookie = basket=”empty”;
//////
function Set_Cookie( name, value )
{
document.cookie = name + “=” +escape( value );
}
////////
// this function gets the cookie, if it exists
function Get_Cookie( name ) {
var start = document.cookie.indexOf( name + “=” );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( “;”, len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}
////////
var total=3;
var facit=new Array()
facit[1]=’Help’
facit[2]=’me’
facit[3]=’please’
var abe=new Array();
abe[1]= ”;
abe[2]= ”;
abe[3]= ”;
var ko=new Array();
////////
function getCellIndex(cell) {
var rtrn = cell.cellIndex || 0;
if (rtrn == 0) {
do{
if (cell.nodeType == 1) rtrn++;
cell = cell.previousSibling;
} while (cell);
rtrn–;
}
return rtrn;
}
////////
function mouse_event (e){
var e = e || window.event;
var obj = e.srcElement || e.target;
var tn = (obj.nodeType == 1)?obj.tagName.toLowerCase():’x’;
while(tn !=”td” && tn != “tbody”){
obj= obj.parentNode || obj.parentElement;
tn = obj.tagName.toLowerCase();
}
if (tn == “td”) {
var idx = getCellIndex(obj);
var id = “c” + ++idx;
document.getElementById(“c1”).className = “”;
document.getElementById(“c2”).className = “”;
document.getElementById(“c3”).className = “”;
document.getElementById(id).className = “hlt”;
Set_Cookie(basket, id);
// document.cookie = basket=id;
}
}
window.onload = function () {
document.getElementById(“binding”).onclick = mouse_event;
};
////////
function pross(numb)
{
var x = Get_Cookie(basket);
if (x==null) {alert(“Først skal du markere en kolonne”)}
else {
var y=x.charAt(1);
if (numb < ko[y])
{
abe[y]=facit[numb] + ” ” + abe[y];
}
else
{
abe[y]=abe[y] + ” ” + facit[numb];
}
ko[y]=numb;
document.all[x].innerHTML = abe[y];
var id = “satn” + numb;
document.all[id].innerHTML = facit[numb];
}
}
</script>
</head>
<Body>
<TABLE BORDER=0>
<TR>
<SCRIPT>
for (q=1;q<=total;q++)
{
document.write(“<TH><DIV ID=’satn” + q + “‘>”);
document.write(“<A HREF=’JavaScript:pross(” + q + “);’>”);
document.write(facit[q]);
document.write(“</A>”);
document.write(“</DIV></TH>”);
}
</script>
</TR>
</TABLE>
<BR>
<table BORDER=1>
<TR>
<TH>FORFELT</TH>
<TH>VERBUM</TH>
<TH>SUBJEKT</TH>
</TR>
<tbody id=”binding”>
<TR>
<TD id=”c1″ HEIGHT=80></TD>
<TD id=”c2″></TD>
<TD id=”c3″></TD>
</TR>
</tbody>
</TABLE>
</BODY>
</HTML>