Populate textbox on radiobutton click

Posted on 2008-11-06
Last Modified: 2012-05-05
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"/>

Question by:mlg101
    LVL 48

    Expert Comment

    by:Ryan Chong
    >>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;

    LVL 4

    Expert Comment

    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.
    LVL 1

    Author Comment

    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?
    LVL 7

    Expert Comment

    could you please copy pastew the browser view source HTML
    LVL 48

    Accepted Solution

    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?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now