Javascript - document.getElementByID

So I have this:

button

1- I’ve given the input field an HTML ID.
2- I’ve setup a basic workflow for the button which includes a basic script to open upon Google is a new tab which works so far.

{
window.open(‘Google’ + ‘term’);
}

2- The issue I’m having or trying to figure out is the function, listener or syntax that would work in Bubble to first give the term a name and value so that I can use the document.getElementByID(‘xxxx’) and then execute my basic script above. Nothing complicated I think but I’m but thought I’d turn to the experts since this is way beyond my capabilities…I have an elementary understanding of HTML, JQuery, Javascript etc… I’m looking for an easy win here…Thanks a bunch!.

Use the toolbox plugin and a page element that comes with it along with an event and action. Here a video that shows you how to set things up

Hope this helps

Thanks so much Carlos for the video recommendation. Can’t wait to give things a try!

@Bubble_clic

Why do you need to use JavaScript for this?

You can just use basic Bubble functionality to access the input’s value… i.e.

windo.open(‘Google’ + ‘Input's value’);

In fact, why do you need to use JavaScript at all here?

Can’t you just use a standard Open External Website Bubble action?

Is there a specific reason for not using vanilla Bubble for this?

2 Likes

Try this, no document.getElementByID(‘xxxx’) required, just pure Javascript (Toolbox plugin)

If you use window.open(url, '_blank') , it will be blocked (popup blocker) on Chrome.

Good question Adam…I’m no doubt making things more difficult than it really needs to be…my nature…I will try your suggestion. thanks.

1 Like

Thanks Jefe…I will try… Cheers.

1 Like

Thanks for the tip on the popup blocker Jeferson. This may sound like a silly question but do I have to create a custom state for Input A’s value first? How the the script make the connection to Bubble’s Input A’s value? I like the simplicity of it.

Hmm like [adamhholmes] said you can do this with native bubble action, i didnt even noticed that lol

just create a button action Open External Website, and the url should be like h ttps://www.google.com/search?q=[YOUR INPUT VALUE]

if you are having trouble opening in a new tab, i suggest you to search for a plugin called ‘Open url tab’ that should do the trick

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.