Welcome Guest!

If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:

  • Receive Fast Advice
  • Learn Programming Languages
  • Get Professional Website Reviews
  • Quick Troubleshooting Assistance

> Why Does This Script Only Work When At The Top?

This is a discussion on Why Does This Script Only Work When At The Top?, within the Javascript section. This forum and the thread "Why Does This Script Only Work When At The Top?" are both part of the Programming Your Website category.

 
Reply to this topicStart new topic
> Why Does This Script Only Work When At The Top?
Karl
post May 31 2008, 09:51 PM
Post #1


Fresh Squeezed
**

Posts: 15
Joined: 13-February 08
From: Richmond, VA


I am making a website for the Philosophy Club at my school, and I wanted to add a search box for the library there. I still haven't gotten permission from the libraries to add it, so it might end-up pointless anyways, but I was hoping you could help me with something.

I don't actually know javascript, so I made this by adapting someone elses'. The thing works, but whenever there are any search boxes that come before it in the HTML then it stops working. And that is really weird, and I am assuming means that I botched something up (even though it works find as long as the entry field is at the top. What needs to change here?

EDIT: It explodes when I try to post it, so instead I am attaching a screen shot.

Thanks for all the help guys!

This post has been edited by Karl: May 31 2008, 09:56 PM
Attached File(s)
Attached File  script.PNG ( 15.22K ) Number of downloads: 15
 
Go to the top of the page
 
+Quote Post
Rakuli
post May 31 2008, 09:59 PM
Post #2


Squeeze Machine
Group Icon

Posts: 763
Joined: 13-February 08
From: Catching the squeezed drips downunder.


Reason is the way you are accessing the form.

document.forms[0].librequest.value will access the first form in the document. Obviously, when there is a form somewhere before yours, it will not be able to find the librequest input in that form.

My suggestion would be to access the form input by id so it doesn't matter where on the page it appears...

CODE
function goTo()
    {
        var url = 'http://catalog.library.vcu.edu.proxy.library.vcu.edu/F?func=find-b';
        var librequest = document.getElementById('librequest').value;
        window.location = url+'&request='+librequest+'&find_code=wrd';
        return false;
    }


Hope that helps.


--------------------
Luke Dingle . com

Turn Over a Playful Leaf on Web Design -- read about the javascript cat
Go to the top of the page
 
+Quote Post
Karl
post Jun 2 2008, 11:59 PM
Post #3


Fresh Squeezed
**

Posts: 15
Joined: 13-February 08
From: Richmond, VA


Sorry it took me so long to thank you! My e-mail account was hacked and I was framed for hacking someone elses' e-mail and I just had a lot going on. sad.gif

But thank you very much for posting this. It works perfectly now! You are like an angel, man! q:
Go to the top of the page
 
+Quote Post
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   12 gribble 555 19th February 2008 - 05:49 AM
Last post by: welshstew
No New Posts   9 PoetAlley 394 17th February 2008 - 06:27 PM
Last post by: PoetAlley
No New Posts 7 Webmaster 744 27th August 2008 - 12:40 PM
Last post by: rich97
No New Posts   1 gribble 361 5th March 2008 - 06:08 PM
Last post by: delusion
No New Posts   1 gribble 228 26th March 2008 - 03:59 AM
Last post by: c010depunkk