Requirement: To open google search on click of a button and search for address in Contact Form Applet.
Issue: Address fields have special characters / which when typed in a URL, browser interprets it as a sub directory or a location in web server.
Solution: This looks pretty simple. We form a calculated expression : "www.google.com?q="+[Field]+"". Open this Link in applet button code. But the above issue is not addressed. for this we can use below function.
escape(String) function: escape function will replace / with %2F which can be understood by browser as / character.
escape("A/B") = A%2FB
Try typing A%2FB in q parameter in google URL and observe the search or do vice versa.
Few escape function that reduce ambiguity to the browser or server to understand and interpret are in this bookshelf link.
Another Example: I want to replace the " in a field value with '. I can use String.replace() method for this. But every " or ' should have a closing " or ' for the compiler to run. For this I used the below expression.
String.replace("/\"/g","\'");
Even though the line has odd number of " and ' , the expression compiles.
/\"/g means replace (\") double quotes globally (g; if you dont give g here, it will replace only the first ") with (\') single quote. The expression should be placed in between / and /.
Issue: Address fields have special characters / which when typed in a URL, browser interprets it as a sub directory or a location in web server.
Solution: This looks pretty simple. We form a calculated expression : "www.google.com?q="+[Field]+"". Open this Link in applet button code. But the above issue is not addressed. for this we can use below function.
escape(String) function: escape function will replace / with %2F which can be understood by browser as / character.
escape("A/B") = A%2FB
Try typing A%2FB in q parameter in google URL and observe the search or do vice versa.
Few escape function that reduce ambiguity to the browser or server to understand and interpret are in this bookshelf link.
Another Example: I want to replace the " in a field value with '. I can use String.replace() method for this. But every " or ' should have a closing " or ' for the compiler to run. For this I used the below expression.
String.replace("/\"/g","\'");
Even though the line has odd number of " and ' , the expression compiles.
/\"/g means replace (\") double quotes globally (g; if you dont give g here, it will replace only the first ") with (\') single quote. The expression should be placed in between / and /.
No comments:
Post a Comment