letItReign letItReign - 3 months ago 22
HTML Question

Dynamic link from a text input

I have a text input and a link below it (I use Webix)
What I want to do is to enter a part of a link (IP address) to the text field and apply this address to a link.

I tried

elements:[
{ view:"text", label:'IP', name:"IPname", id:"IPid", value:"127.0.0.1" },
{ view:"template", height: 30,
template:"<span><a href='' onclick='"+window.open($$("IPid").getValue()+"'>Test link</a></span>"
}
],


But this notation doesn't work (actually, gives an error "IPid is undefined")

My Code Here

Is there any way to do this?

Answer

Strange issue, I'm not very familiar with webix, but putting the window.open in a function worked. Also have in mind that the correct attribute is 'onclick' not 'click' and that a parenthesis was missing. Fixed them too, check it out: http://webix.com/snippet/e4e236b9

webix.ui({
  rows:[
    {
      id:"form1", view:"form", scroll:false,            
      elements:[
        { view:"text", label:'IP', name:"IPname", id:"IPid", value:"127.0.0.1" },
        { view:"template", height: 30, 
         template:"<span><a href='' onclick='fixLink()'>Test link</a></span>" 
        }        
      ],
      width: 320,
      elementsConfig:{        
        labelPosition: "top",        
      }
    }       
  ]    
});

<script>
function fixLink(){  
  window.open('http://'+$$("IPid").getValue());
}
</script>