g_form.getDisplayBox('reference field').value does not return values with '&'

Lathashree Ling
Kilo Contributor

I am using g_form.getDisplayBox('reference field').value in a UI action as below.

function searchCompany() {
var url = 'http://www.bing.com/search?q=';
var company = (g_form.getDisplayBox('reference_field').value);
window.open(url + company , '_blank');
}

For example, Reference field value = Apple & Pie, the URL searches just 'Apple'

However, it works fine for values with , and space. Just the '&'. Any thoughts?

 

 

1 ACCEPTED SOLUTION

Try this...

function searchCompany() {
    var url = 'http://www.bing.com/search?q=';
    var company = (g_form.getDisplayBox('u_group').value);
    company = encodeURIComponent(company).toString();
    window.open(url + company);
}

View solution in original post

12 REPLIES 12

Whereas this solution may work for your specific use case of the problematic "&" character, you are better off encoding the company name as both Chuck and Mark suggested.  This will work with any problem characters:

function searchCompany() {
	var url = "http://www.bing.com/search?q=";
	var company = encodeURIComponent((g_form.getDisplayBox("company").value));
	window.open(url + company , "_blank");
}

You are better off using the encodeURIComponent function now instead of running into an issue with another character later on.

Thats what I did 🙂

OK, that's good.  Thanks for the update.