Page 1 of 1

open url with field variable

Posted: Sun Jun 17, 2018 11:45 am
by amit
Hi guys,

I have a problem. I'm trying to open a website when a button is clicked. So I added an onclick event to the button that calls window.open .
The website opens but my variable, #cust_product# is not resoloved, it should be replaced with the content of the field on my form.
btnopen.png

Re: open url with field variable

Posted: Sun Jun 17, 2018 7:40 pm
by nac
Amit,

Here is how I did something similar. I was using an input:URL object to store the URL and doubleclick on it would run the code below to open the website. You could easily attach this code to a button onclick and pull the URL from another field if you wish. I am assuming that cust_product holds the URL you wish to open.

Code: Select all

var myURL =  $("#cust_product").val();   // change to your object name as required
//   var myURL = $(this).val();    // use 'this' if it is the element itself that is clicked

if (myURL.length > 0) {
      if (myURL.indexOf("://") < 0) {  // check to see if the scheme prefix is present.
           myURL = "http://" + myURL  // if not add http.
       }
     window.open(myURL, '_blank');
}
I hope this helps.

Neil

Re: open url with field variable

Posted: Sat Jun 30, 2018 12:07 am
by admin
.