• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

Populate textbox on radiobutton click

I have a texbox named "ServeeAddress1" with text in it, which I need to send to the 2nd textbox, "ServedAddress" when i click a radiobutton, so they both then have the same text. Here is the code I tried and it is not working. I get an error in the javascript that says, "object required"

<script type="text/javascript" language="javascript">
function setText()
document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1").value == document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel5_ServedAddress").value;

<asp:RadioButton ID="Radio1" runat="server" Text="Address 1" onclick="setText();"  />

<asp:textbox id="ServeeAddress1" runat="server"/>
<asp:textbox id="ServedAddress runat="server"/>

1 Solution
Ryan ChongCommented:
>>document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1").value == document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel5_ServedAddress").value;

should be as:

document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1").value = document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel5_ServedAddress").value;

Two equals signs checks equality between two things (like in an if statement), 1 equals sign is for when you are assigning a value to something.
mlg101Author Commented:
OK, I tried that, thank you, but it still doesnt work. Now the error says document.getElementById is Null or not an object. any ideas?
could you please copy pastew the browser view source HTML
Ryan ChongCommented:
can help double check what is "ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1" in your page? Is it a form element, or a layer (div), etc? if it's a layer, try use innerHTML instead, like:

document.getElementById("ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1").innerHTML = "new value";

of course, before that, make sure object "ctl00_ContentPlaceHolder1_tabcontainer1_tabpanel4_ServeeAddress1" exists in your page?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now