pcdl>> Det er lidt svært, når man ikke ved, præcis hvordan det fungerer. F.eks. måtte jeg indføre nogle if-sætninger, som tjekkede, om de forskellige beholdere allerede indeholdt tekst, inden jeg kunne bruge koderne. Men mit bud er følgende:
var maxwords = 250;
var titlewords = 65;
function check_length(obj, cnt, rem, text)
{
if(!document.getElementById("desc").hasChildNodes())document.getElementById("desc").appendChild(document.createTextNode(" "));
if(!cnt.hasChildNodes())cnt.appendChild(document.createTextNode(" "));
if(!rem.hasChildNodes())rem.appendChild(document.createTextNode(" "));
if(text==""){
document.getElementById("desc").firstChild.nodeValue="Din beskrivelse her";
cnt.firstChild.nodeValue = "0";
}else{
var o=document.getElementById("desc");
text=text.split(" ");
for(var i=0;i<text.length;i++){
o.appendChild(document.createTextNode(text[i]+" "));
if((i+1)%100==0)o.appendChild(document.createElement("br"));
}
var ary = obj.value.split("");
var len = ary.length;
cnt.firstChild.nodeValue = len;
rem.firstChild.nodeValue = maxwords - len;
if (len > maxwords) {
alert("Message in '" + obj.name + "' limited to " + maxwords + " words.");
ary = ary.slice(0,maxwords-1);
obj.value = ary.join("");
cnt.firstChild.nodeValue = maxwords;
rem.firstChild.nodeValue = "0";
return false;
}
}
return true;
}
function check_title_length(obj1, cnt1, rem1, text1, text2)
{
if(!document.getElementById("title").hasChildNodes())document.getElementById("title").appendChild(document.createTextNode(" "));
if(!cnt1.hasChildNodes())cnt1.appendChild(document.createTextNode(" "));
if(!rem1.hasChildNodes())rem1.appendChild(document.createTextNode(" "));
if(text1==""){
document.getElementById("title").firstChild.nodeValue="Din titel her";
cnt1.firstChild.nodeValue = 0;
}else{
if(document.getElementById("title").hasChildNodes())document.getElementById("title").removeChild(document.getElementById("title").firstChild);
document.getElementById("title").appendChild(document.createElement("a"));
document.getElementById("title").firstChild.setAttribute("href","
Http://" + text1);
document.getElementById("title").firstChild.firstChild.nodeValue=text2;
var ary = obj1.value.split("");
var len = ary.length;
cnt1.firstChild.nodeValue = len;
rem1.firstChild.nodeValue = titlewords - len;
if (len > titlewords) {
alert("Message in '" + obj1.name + "' limited to " + titlewords + " words.");
ary = ary.slice(0,titlewords-1);
obj1.value = ary.join("");
cnt1.firstChild.nodeValue = titlewords;
rem1.firstChild.nodeValue = "0";
return false;
}
}
return true;
}
function check_url_length(text1, text2)
{
if(document.getElementById("title").hasChildNodes())document.getElementById("title").removeChild(document.getElementById("title").firstChild);
if(!document.getElementById("url").hasChildNodes())document.getElementById("url").appendChild(document.createTextNode(" "));
if(!cnt1.hasChildNodes())cnt1.appendChild(document.createTextNode(" "));
if(!rem1.hasChildNodes())rem1.appendChild(document.createTextNode(" "));
if(text1==""){
document.getElementById("url").firstChild.nodeValue = "
Http://Dit-link.dk"; cnt.firstChild.nodeValue = 0;
}else{
document.getElementById("url").firstChild.nodeValue='
Http://' + text1;
document.getElementById("title").appendChild(document.createElement("a"));
document.getElementById("title").firstChild.setAttribute("href","
Http://" + text1);
document.getElementById("title").firstChild.firstChild.nodeValue=text2;
return true;
}
}
Ved selvfølgelig ikke, om det vil virke.