Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

get Value of textbox / input-field

BennySHS (Programmer) (OP)
27 Oct 05 5:55
Hi there,

I'm trying to read the value of a textbox and/or a hidden input field.

I tried the following code:
and        alert(document.getElementById('bereich').value);

and both doesnt work. I goolged for a while to find other solutions, but they are all the same as mine.
Is there a obvisiuos mistake i make ?

I use Firefox 1.07 but in IE it doesn't work to.

Hope you can help me,
thx in advance.
greets ben
tsuji (TechnicalUser)
27 Oct 05 6:14
The correct line is your second line.
If it does not, you have mistake elsewhere and the alert has never been reached.
BabyJeffy (Programmer)
27 Oct 05 6:38
As Tsuji says, the correct alert is the second one. You may not be getting the value alerted for many reasons - including missing the id on the input. You also want to make sure you do not attempt to access the DOM until after the page has loaded (and the onload event has triggered).


Jeff's Page @ Code Couch

BennySHS (Programmer) (OP)
27 Oct 05 6:44
hi guys,

thx a lot for your answers.

>You also want to make sure you do not attempt to access the >DOM until after the page has loaded (and the onload event has >triggered).

Guess that's the problem.

I tried to get the Value of the element in a if-condition at the top of the page.
Its more then logic that the DOM can't access the element right now...

Ok so I'll find another way to do this ;)
Thx a lot!
theniteowl (Programmer)
27 Oct 05 7:16
Replace the alert with a basic alert("Got here"); and see if that fires.  Then you know if it is the logic getting to that point or the actual reading of the value.

Make certain your field has an ID tag.  Try:
<input type="text" id="bereich" value="Testing">

And at what point do you execute the code with the alert?
As BabyJeffy said, it has to occur after the page has been fully loaded.
Perhaps try even putting your alert in an onload statement in the body tag for testing.

Paranoid?  ME??   WHO WANTS TO KNOW????

cLFlaVA (Programmer)
27 Oct 05 8:40
i have two suggestions.  you could either

1) place the code at the bottom of your page:



  <script type="text/javascript"><!--

or 2) place the code in a function and call it from the body's onload event.



<script type="text/javascript"><!--
function doSomething() {    
  <body onload="doSomething();">

your mom goes to college

tsdragon (Programmer)
27 Oct 05 8:42
You can also add the parameter [b]defer]/b] to your script tag. That will keep it from running until the page has been loaded.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.

LFI (Programmer)
27 Oct 05 9:28

I hadn't heard of defer before, but upon looking it up, I see it might not have cross-browser support (introduced for IE originally) and, it appears, that great care must be used in using it.  More information at

I'm curious if there is a benefit to using defer versus the BODY tag's ONLOAD event.

Opera seems to have something called DOMContentLoaded ( which operates like defer.  I'm not sure what other browsers do.


O Time, Strength, Cash, and Patience!  

chmohan (Programmer)
27 Oct 05 11:19
is the id  correct?  i mean is is spelt correctly and all?
you could try Elements["nameofyourelement"].value right?
BabyJeffy (Programmer)
27 Oct 05 11:26
From a few posts back...


Guess that's the problem.

I tried to get the Value of the element in a if-condition at the top of the page.

I suggested that he not attempt to access the DOM until the onload event has triggered. His reply indicates he was running some JS in the page as it was loading.

So... unless it turns out to be something else, I think we've cracked this one


Jeff's Page @ Code Couch

BennySHS (Programmer) (OP)
28 Oct 05 3:37
Hi there,

thx to all for the much replies and tips.

I'll explain short what I wanted to achive:

On my pages are two forms. Every form has its own submit-button.
Now when submitting form b I wanted to access via JS the content of form A. And the access to the content of form A happened during the pages was not finished loading.

I'll do a workaround to set a hidden-field in form B with the content of form A with an onclick, and then I can access the fields of form B via php.

Sorry guys I guess I should had explained my intention a littlebit earlier, so I would have saved you some writing..

Thx a lot again,
greets ben

ps: sorry for the bad grammar
LFI (Programmer)
28 Oct 05 9:25

If I understand you correctly, then you can just keep the button that submits form B disabled until the forms finish loading.


<body onload='document.forms["formB"].submitButton.disabled = false;' />

<input name='submitButton' type='Submit' disabled />

'hope this helps.


O Time, Strength, Cash, and Patience!  

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close