Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#set($cusFieldVarName="title")
<script>
function updateDisplayURLTitle(){
// get the title entered by the user
var plainTitle = dojo.byId("$cusFieldVarName");
if(plainTitle == undefined || plainTitle.value.length ==0){
dojo.byId("displayURLTitle").innerHTML = "";
dojo.byId("urlTitle").value="";
return;
}
// make a friendly url
var urlTitle = plainTitle.value.toLowerCase();
urlTitle= urlTitle.replace(/^\s+|\s+$/g,"");
urlTitle = urlTitle.replace(/[^a-zA-Z 0-9]+/g,' ');
urlTitle = urlTitle.replace(/\s/g, "-");
while(urlTitle.indexOf("--") > -1){
urlTitle = urlTitle.replace("--",'-');
}
while(urlTitle.lastIndexOf("-") == urlTitle.length -1 ){
urlTitle=urlTitle.substring(0,urlTitle.length -1);
}
// set the values of the display place holder and the custom field
// the is to hold the div open
dojo.byId("displayURLTitle").innerHTML = urlTitle;
dojo.byId("urlTitle").value=urlTitle;
}
// attach this the text1 field onchange
dojo.addOnLoad(function(){
dojo.connect(dojo.byId("$cusFieldVarName"), "onchange", null, "updateDisplayURLTitle");
}
);
// populate the field on load
dojo.addOnLoad(updateDisplayURLTitle);
</script>
<div id="displayURLTitle" style="height:20px"> </div>