Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Input tag value not displaying

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
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
 
Hi

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

But why you [tt]getElementById()[/tt] when you already have that element in [tt]this[/tt] ?
HTML:
[b]<input[/b] [maroon]value[/maroon][teal]=[/teal][i][green]"ABC"[/green][/i] [maroon]onclick[/maroon][teal]=[/teal][i][green]"alert(this.value)"[/green][/i][b]>[/b]

Feherke.
feherke.github.io
 
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="[b]nothing[/b]" 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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top