div tex in texbox on click

Discussion in 'JavaScript' started by jijihuqw, Jul 4, 2011.

  1. #1
    Hi
    I have a page containing more than 50 divs. every div contain uniq user name (eg. name of students). In this page there is also a textbox. Now I want that when I click on any div. textbox value will the value of that div. how can I do that
     
    jijihuqw, Jul 4, 2011 IP
  2. vruvishal

    vruvishal Member

    Messages:
    22
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    Hi,
    for eg. <div id="div_1">Hello</div>
    <input type="text" id="text_1" name="text_1" value="new hello" onclick="javascript:updateDivVal('1') />

    function updateDivVal(id){
    document.getElementById('div_'+id).innerHTML=document.getElementById('text_'+id).value;

    }


    Vishal
    vruvishal@gmail.com
     
    vruvishal, Jul 4, 2011 IP