INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

*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

Text Input tag value not displaying

Text Input tag value not displaying

(OP)
I'm trying to dynamically change the value of this tag when clicking on another element on this document. It wasn't working and I wasn't getting an error. So, to trouble shoot I placed this alert in the onclick event of the tag.

In example (1) I get an empty alert box.
When I change it to example (2) I GET 0 in the alert box.

I'm missing something. Any help appreciated.

CODE

<form name="getSSN1" id="getSSN1" action="IRSLookup.cfm" method="post" enctype="multipart/form-data">

1. <input type="text" size="35" id="RECIPIENT2" name="RECIPIENT2" value="ABC" onclick="alert(document.getElementById(this.id).value)">
2. <input type="text" size="35" id="RECIPIENT2" name="RECIPIENT2" value="ABC" onclick="alert(document.getElementById(this.id).value.length)">
</form> 

Lyndon

RE: Text Input tag value not displaying

Hi

Your example works for me in FireFox : I get "ABC" for (1) and "3" for (2).

But why you getElementById() when you already have that element in this ?

CODE --> HTML

<input value="ABC" onclick="alert(this.value)"> 

Feherke.
feherke.github.io

RE: Text Input tag value not displaying

Works for me too. Though do note that getElementById will only ever return the first item it finds with that id. In your case both of your alerts would be getting the value form the first input, even though one is being run inside the second input.

So if you have more than one element with the ID of "Recipient2" it may me getting one that does not have a value attribute set, or one that is empty.

For example if you had this:

CODE

<form name="getSSN1" id="getSSN1" action="IRSLookup.cfm" method="post" enctype="multipart/form-data">

1. <input type="text" size="35" id="RECIPIENT2" name="RECIPIENT2" value="nothing" onclick="alert(document.getElementById(this.id).value)">
2. <input type="text" size="35" id="RECIPIENT2" name="RECIPIENT2" value="ABC" onclick="alert(document.getElementById(this.id).value.length)">
</form> 

You will always get "nothing" and it will never be able to get the value of the second input box "ABC".

----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: Text Input tag value not displaying

(OP)
I never put the example input tags in the document at the same time.

I was paring down the example because this document is a huge, dynamically constructed grid, often thousands of lines when in use. The "RECIPIENT2" id's have a unique extension appended onto them using the query.currentrow value in the constructor loop.

I'm not sure how to proceed just now but posting a 12,000 line server side example seemed unreasonable... I'll have to work on a way to pare it down some and block personal privacy data.


Thanks all.

Lyndon

RE: Text Input tag value not displaying

You don't need to post 12,000 lines of code.

Try Feherke's suggestion first, to eliminate an issue with the IDs. Even if there is another element with the same ID for any reason it won't matter if you are not using it.

If using Feherke's suggestion you still get no value and no length, then the issue stems with the value that the server side code is producing or when its producing.



----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: Text Input tag value not displaying

(OP)
Thanks All,
I'm going to try and post server side code in the ColdFusion forum. I'll come back and post solution if found.

Lyndon

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

Resources

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