how to fill a div text from text on a form both on load and change of text in form

Posted on 2007-07-26
Last Modified: 2012-06-21
i came across this code
<div id=a>Filled with text</div>

<div id=b onclick="document.getElementById('a').innerHTML='Some Text'">Click Me</div>
how do i get it to change from my form text (upon load and upon change)

          <input   size="36" maxlength="35" value="<?php echo $Manufacturer;?>" name="Manufacturer" onChange="updatePicLink('')">

how do i put all this together

thank you in advance for any code and help you may provide.
Question by:Johnny
    LVL 18

    Expert Comment

    i'm not sure i understand exactly what you want to happen, can you elaborate?
    LVL 14

    Accepted Solution

    ok, so, you have a div, that you want to change to what is in the Manufacturer textbox, when the page loads, and anytime the Manufacturer textbox value changes? why change it, if you can just set it the same on the server...?

    something like:

    <div id="a"><?php echo $Manufacturer;?></div>
    <input value="<?php echo $Manufacturer;?>" name="Manufacturer" onChange="document.getElementById('a').innerHTML=this.value;" size="36" maxlength="35">
    LVL 17

    Expert Comment

    Probably this is what you are looking for:

                      <title>Script Demo Gops</title>
                      <script language="javascript">

                            function updatePicLink(v){
                                  var o=document.getElementById('a');
          <div id="a"></div>
          <form name="test">
                <input name="Manufacturer" type="text" value="Manufacturer" onChange="updatePicLink(this.value)">

    Author Comment

    steveberzins is what im looking for kinda

    im trying to show the value of the manufacturer value to the div as it loads and we have the onload part with the php statement(duh shoulda thought of that myself)

    now the string we have is printing out
    as the text and not the value.. if we get this part fixed where all set. by the way the line has to have the updatepic too
    so it read right now as
              <input   size="36" maxlength="35" value="<?php echo $Manufacturer;?>" name="Manufacturer" onChange="document.getElementById('a').innerHTML=this.value; updatePicLink('')">

    thanks so far for the help and suggestions

    Author Comment

    duh it does work i had the statement in the updatepic i was trying to get to work...forgot that one

    so it does work thanks again
    accepting steveberzins as answer as his was not only the one i used but the first working answer

    Author Comment

    heres my final code snips so others can see how it works

    <script language="JavaScript" type="text/javascript">
    function updateDiv() {
    document.getElementById('a').innerHTML = "Current Product - <?php echo $ID;?>: " + document.demoform.Manufacturer.value + ", " + document.demoform.Type.value;

              <input size="36" maxlength="35" value="<?php echo $Manufacturer;?>" name="Manufacturer" onChange="updateDiv(''); updatePicLink('')">

     <div align="left" id=a>Current Product - <?php echo$ID;?>: <?php echo $Manufacturer;?>, <?php echo$Type;?></div>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    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…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now