Javascript problem

My javascript won’t work, do you now the problem/ a solution?
(I’m not so of a javascript coder, and I am making a files search)

<script>
document.body.innerHTML = '<textarea><\/textarea>';
document.body.innerHTML += '<a href="/Storage/'+ textarea +'>Search<\/a>';
</script>

It would help if you told us what you want your code to do. The small code sample you’ve given is quite hard to interpret. :grin:

So I am making a file finder, you type some text in a textarea and there is a link then that link will href what you have typed in the textarea. But the code doesn’t seem to work. Sorry if that ain’t enough info :neutral_face:

Sorry, this is a help forum for Caddy, and this doesn’t really seem related in any way. You’ll get better help from other places like StackOverflow.

While that’s true, most of us here are either web developers, sysadmins, or Go programmers. Even though Stack Overflow has an infinitely larger audience and they’ll probably get an answer faster there, I think our community could do with a little related variety from the usual “Caddy isn’t working” humdrum we see all day, every day. I personally think it’d be invigorating to see more discussion about the modern Web and Web development on a forum about a web server.

1 Like

This is one way of doing it. :slight_smile: I hope that you find it useful.

<textarea id="search-box"></textarea>    
<a id="search-link" href="#">Search</a>    
                                           
<script>    
  document.getElementById('search-link').addEventListener('click', (e) => {    
    e.target.href = '/Storage/' + document.getElementById('search-box').value    
  })                                                                             
</script>  

This snippet listens out for the search link being clicked. When it is clicked, it changes the href before the page changes.

3 Likes

Thank you!

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.