Current location: Hot Scripts Forums » General Web Coding » JavaScript » Creating a link to anchor text using javascript pull-down


Creating a link to anchor text using javascript pull-down

Reply
  #1 (permalink)  
Old 03-06-07, 07:36 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Creating a link to anchor text using javascript pull-down

this is how my pull-down looks:

HTML Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
// End -->
</SCRIPT>

<center>
<form name="form">
<select name="site" size=1 onChange="javascript:formHandler()">
<option value="">Choose Paragraph

<option value="#Paragraph1"> Paragraph 1 </option>
<option value="#Paragraph2"> Paragraph 2 </option>
<option value="#Paragraph3"> Paragraph 3 </option>

</select>
</form>
</center>
Further down on my page here is my anchors:

HTML Code:
<a name="Paragraph1">Paragraph 1</a>
<a name="Paragraph2">Paragraph 2</a>
<a name="Paragraph3">Paragraph 3</a>
This doesn't work. What am I doing wrong?

I'm pretty sure its with these lines:
HTML Code:
<option value="#Paragraph1"> Paragraph 1 </option>
<option value="#Paragraph2"> Paragraph 2 </option>
<option value="#Paragraph3"> Paragraph 3 </option>
Thanks in advance.

Last edited by Nico; 03-07-07 at 02:28 AM.
Reply With Quote
  #2 (permalink)  
Old 03-07-07, 04:03 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
Are you sure there's enough space between the different anchors? If they're all in view, your browser won't really scroll to them.

Besides that, try changing this in your javascript code, assuming that URL has the correct value:

Code:
window.location = window.location + URL;
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #3 (permalink)  
Old 03-08-07, 03:20 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, there is alot of space between the anchors. I tried replacing the line and it still doesn't work.

Is something wrong with this?

Code:
<center>
<form name="form">
<select name="site" size=1 onChange="javascript:formHandler()">
<option value="">Choose Paragraph

<option value="#Paragraph1"> Paragraph 1 </option>

<option value="#Paragraph2"> Paragraph 2 </option>

<option value="#Paragraph3"> Paragraph 3 </option>


</select>
</form>
</center>
Reply With Quote
  #4 (permalink)  
Old 03-09-07, 02:23 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not sure if that's the problem, but in the onChange, you don't have to set "javascript:". Just make it like this:
Code:
<select name="site" size=1 onChange="formHandler()">
To make things easier, you could even do it like this:
Code:
<select name="site" size=1 onChange="formHandler(this)">
But then you'll need to modify your formHandler function accordingly:
Code:
function formHandler(selectbox){
var URL = selectbox.options[selectbox.selectedIndex].value;
window.location.href = URL;
}
Hopefully this works for you now
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #5 (permalink)  
Old 03-09-07, 01:48 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you. works well
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help in JavaScript link to open a Folder ferenczi JavaScript 3 01-19-07 04:45 AM
Javascript (pull the filename) pcinfoman JavaScript 2 02-23-06 03:50 PM
Six Sites Exchanging Links! - PR3+ Web Hosting, Web Design, Entertainment & Career coffeecoder General Advertisements 0 10-10-05 12:52 AM
Xml / Dom / Css Mark_SC.SE JavaScript 0 06-29-05 08:05 AM
Javascript that clicks on a link onload? decemuirs JavaScript 2 06-16-05 07:05 AM


All times are GMT -5. The time now is 11:25 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.