PDA

View Full Version : "custom location bar"



ryoung
01-27-2009, 05:08 PM
I'm trying to get a variation of the CUSTOM LOCATION BAR on http://www.sivamdesign.com/scripts/navigate.html (code can be found at http://www.sivamdesign.com/scripts/dwld/location.txt )to work.

Basically, I want to have users enter a string (e.g., 1234) into a text box, click on the GO button, and then be taken to
http://domain.com/page.php?1234

Is that possible, and if so, how is it done?

Any help is greatly appreciated!

Nile
01-28-2009, 04:02 AM
Here you go:


<script type="text/javascript">
var locateTo = function(els){
window.location.href = "page.php?"+els.elements['locate'].value;
};
</script>
<form action="page.php" method="get" onsubmit="locateTo(this); return false; ">
<input type="text" name="locate"/><input type="submit" />
</form>

You should also make this compatible with javascript disabled users. To do this, on page.php, add:


<?php
if(isset($_GET['locate'])) {
header("Location: ".$_SERVER['PHP_SELF']."?".$_GET['locate']);
}
?>

Of course - if you do that then all you need to do with the <form> I gave you 2 codes above is:


<form action="page.php" method="get">
<input type="text" name="locate"/><input type="submit" />
</form>

Which I highly suggest.