Changing the value of an input field into a link

With this function it is possible to change the input of an inputfield into a link and to provide TIM users with it. Herefor the initMethod has to be given in the smartform, which is called in the custom.js

<?xml version="1.0" encoding="utf-8"?>
<form name="SFname" initMethod="initChangeHref">
<table style="border:1px solid #aaaaaa;">
<tr>
<td>
<input type="text" name="input_path" class="input_path" id="input_path" />
</td>
</tr>
<tr>
<td>
<a target="_blank" name="link" id="link" style="text-decoration:none;"/>
</td>
</tr>
</table>
</form>

Now the initMethod has to be created in the custom.js. In it jq has to be included, the onChange method has ot be bound to the input field and the input has to be given to the link. Additionally the function checks whether the input already contains 'http:/ /' or 'https:/ /'. If not, 'http:/ /' is set befor the link (without the space between the slashes).

gadget.functions.initChangeHref=function(){
jq= (this.form.ownerDocument.defaultView!=null) ? this.form.ownerDocument.defaultView.jQuery : this.form.ownerDocument.parentWindow.jQuery;
window['entity'] = this.entity;
jq('#input_pfad').change(function(){
var atag= jq("#link")[0];
if(this.value.indexOf('http://')==-1 && this.value.indexOf('https://')==-1){
atag.href = 'http://' + jq.trim(this.value);
atag.innerHTML = atag.href;
window['entity'].setValue(atag.id, 'http://' + jq.trim(this.value));
}
else{
atag.href = jq.trim(this.value);
atag.innerHTML = atag.href;
window['entity'].setValue(atag.id, jq.trim(this.value));
}
window['entity'].setValue(this.id, this.value);
window['entity'].mergeLocal(true);
});
}