• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

anchor search box

Pronoun
he/him
I would like to have a search box and a button on on .shtml page so that when the button is clicked, the user is directed to the page anchor that was typed into the box (so "thepage.shtml/#anchor"). I put it in this forum as I am pretty sure that it will have to be something more complex than html.

Thanks!
 
Do you mean something like a "search the page" function? If so, why can't people just use the one their browser has?

Or do you mean you want the search box on one page that goes to a specific anchor on a different page when the button is clicked?
 
by number, try something like this, altered to work for your language:

Code:
printf("location:%s#%03d\n\n", $ENV{SCRIPT_NAME}, $cgi->param("input"));

where $ENV{SCRIPT_NAME} is a variable containing Exactly What It Says On The Tin, and $cgi->param gets a parameter (in this case, "input").
 
Put this under where it says "Go forth and spell better!":

HTML:
<form action="#" method="get" onsubmit="location.href='#'+document.getElementById('pokemonNumber').value; return false;">
  <p>Type the Pokémon's number here: <input type="text" name="pokemonNumber" id="pokemonNumber" value="001" /> <button type="submit">Submit (or press enter)</button></p>
</form>

The onsubmit attribute is a piece of JavaScript which sends you to whichever anchor has the id you typed in the box (the location.href part) and then stops the form from actually submitting (the return false part).
 
thanks to both of you - it works now!

If it's possible, could someone modify the code so that it adds any necessary zeros before the number (eg. if they type in "45" it goes to anchor "045")

it's good enough as it is, but that woud make it perfect!

Thanks.
 
You could also just make a simple function, such as this:

Code:
<script type="text/javascript">
function padnum(s) {
   while (s.length < 3) {
      s = "0" + s;
   }
   return s;
}
</script>

And then you can just run the number from the form through padnum, i.e. use padnum(document.getElementById('pokemonNumber').value) instead of just document.getElementById('pokemonNumber').value.
 
where do I put that code? Is that all the code I need?

sorry, but I can't code in javascript, so your going to have to do it step by step XD
 
You would put that code somewhere in the head section of the page (or the body, if you want, I guess, as long as it comes before the search box), and then in the code that Max Elixir gave you, put padnum(document.getElementById('pokemonNumber').value) instead of just document.getElementById('pokemonNumber').value.
 
thanks butterfree - it works now!

also, thanks for the generator in which this page was created

I think Im going to have to send you a present for being so helpful...
 
Back
Top Bottom