Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2011, 02:10 AM   PM User | #1
anarch
New Coder

 
Join Date: Jun 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
anarch is an unknown quantity at this point
Need a little help

Ok, this should be easy but for me it doesn't seem so... probably because i'm very close to the deadline and have a lot to do.

This is what i'm trying to do;
I have an html form with a textfield and a button - whenever the button is clicked or enter is pressed i would like it to goto a particular page and place the text field's value on the end as a hash.

for instance;
user enters "test" and presses enter or hits the button and the page goes to "google.com#test"'

edit: to clarify I would like it to add the hash on the end of the href for the page it should goto

Last edited by anarch; 07-01-2011 at 02:55 AM..
anarch is offline   Reply With Quote
Old 07-01-2011, 02:59 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Lightbulb

Code:
<!DOCTYPE HTML>
<html>
<head>
<title> Untitled </title>
<script type="text/javascript">
function GoTo() {
  document.location = "http://www.google.com#"+document.getElementById('hashContent').value;
}
</script>

</head>
<body>
Go to www.google#<input type="text" id="hashContent" value="">
<button onclick="GoTo()">Go</button>
</body>
</html>
Of course you realize that if the user miss-types the hash, it won't go where you want.
jmrker is offline   Reply With Quote
Old 07-01-2011, 03:16 AM   PM User | #3
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
it's probably a good idea to encodeURIComponent() the user input.
bullant is offline   Reply With Quote
Old 07-01-2011, 04:03 AM   PM User | #4
anarch
New Coder

 
Join Date: Jun 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
anarch is an unknown quantity at this point
it doesn't matter what they type because it's a search field. I have to use the url bar to transfer information across joomla mods from one page to another.
That method didn't work at all even with URI encoding.

without uri encoding all it does is add "searchTerm=" to the url bar - with uri encoding it does get the word up there but not beginning with a # nor does it go to the page
anarch is offline   Reply With Quote
Old 07-01-2011, 04:32 AM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Question

Quote:
Originally Posted by anarch View Post
it doesn't matter what they type because it's a search field. I have to use the url bar to transfer information across joomla mods from one page to another.
That method didn't work at all even with URI encoding.

without uri encoding all it does is add "searchTerm=" to the url bar - with uri encoding it does get the word up there but not beginning with a # nor does it go to the page
So, bottom line is that neither suggestion helped?
jmrker is offline   Reply With Quote
Old 07-01-2011, 04:39 AM   PM User | #6
anarch
New Coder

 
Join Date: Jun 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
anarch is an unknown quantity at this point
Unfortunately not. -_-

I already tried yours before coming here lol. I'm not sure why this is so complicated really... lol.
anarch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:05 PM.


Advertisement
Log in to turn off these ads.