Help - Search - Members - Calendar
Full Version: Javascript Question
Invision Power Services > Community Forums > Community Web Design and Coding
Phil Mossop
I'm linking to a JS script in the <head> part of my page. How can I get the value of a text input on this page? If I include the JS in full in the heqader section rather than linking I can use document.name.field.value but if I link it doesn't seem to like that.
IAIHMB
If I understand what you're saying, you've got to let the page load first. Simon Willison's addLoadEvent() is an option, as is the following if you're only executing one function on page load:

CODE
window.onload = function();


"window" could be replaced with "document" if it amuses you, as far as I know there is no difference.

Edit: Maybe this is what you're after. You've got to get ahold of the input, there are a number of ways of doing this. If it's got an id:

CODE
document.getElementById("...").firstChild.nodeValue;
document.getElementById("...").value;


You could also use getElementsByName:

CODE
document.getElementsByName("...")[0].firstChild.nodeValue;
document.getElementsByName("...")[0].value;
Phil Mossop
Edit: Nevermind I fixed it. Forgot to put the name attribute on my form tag. Doh! pinch.gif Thanks anyway!

Hmm, what I mean is, if I include a script like this:

CODE
<script type='text/javascript' src='jscripts/unis_step1.js'>


document.whatever doesn't seem to work, I get this error:

CODE
message: Statement on line 9: Could not convert undefined or null to object
Backtrace:
  Line 9 of linked script http://localhost/ucas/jscripts/unis_step1.js
    send = document.uni.grades.value;
  Line 1 of  script
    fetch_convert("grades");
  At unknown location
    [statement source code not available]


I think that is the problem anyway, not really sure!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.