Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Input to auto write

    I have a form with hidden <SPAN>'s.

    <SPAN> one has an <INPUT> text field, whose string value I'd like to repeat in <SPAN> two.

    The repeated value should appear as text in the page and not within another <INPUT> field.

    The only method I've learned is the following. But re-loading the page resets all other form fields. (An example I found on Codingforums.)
    Code:
    <script>
    function process1() {
    document.getElementById("B1").value = (document.getElementById("A1").value);
    }
    </script>
      <input id="A1" type="text" value="Enter something here" onClick="value=''">
      <input type="button" value="GO" onClick='process1()'>
      <input id="B1" type="text" value="" disabled="disabled">

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Here is an example of one method:
    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    function dup(obj,t) {
    document.getElementById(obj).appendChild(document.createTextNode(t));
    }
    /*]]>*/
    </script>
    
    <form id="f" method="post" action="" enctype="multipart/form-data">
    <input type="text" id="txt" value="" size="32" maxlength="300" onchange="dup('b',this.value)" />
    </form>
    
    
    
    <span id="b"></span>
    re-loading the page resets all
    That's what I'd expect
    Last edited by rwedge; 05-14-2007 at 11:42 PM.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. I'd been trying the "write" command too but found it didn't do what I'd hoped. (Much like the reload.)


  • #4
    New Coder
    Join Date
    Jan 2006
    Location
    Cairo, Egypt
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Welcome everybody...
    I think this is your needs.
    Code:
     
    <script>
    function process1() {
    document.getElementById("B1").innerText = document.getElementById("A1").value;
    }
    </script>
    <input id="A1" type="text" value="Enter something here" onClick="value=''">
    <input type="button" value="GO" onClick='process1()'>
    <span id="B1"></span>
    Khaled Mahmoud
    Web, Flash, Games developer.
    JavaScript reference VBScript reference ASP reference

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question replacing old variable value

    JavaScript is writing input field values as text.

    Thanks you for your support.

    I have another question about replacing the written text.

    What's currently happening:

    Say a user provides info in the text field and continues on with the form. (The text field info is written to the page by JS.)
    The user realizes they made an error and go back to edit the text field. Once done, the page is updated again by JS.
    BUT, the new value is added to the old value.

    I'd like the new value to always replace the old value instead of adding to it.

    Would I have to use <div> instead of <span> tags just to reset an object's value element? I'd rather use <span> tags.

    Working with the following example by Khaled Mahmoud:
    Code:
    <script>
    function process1() {
    document.getElementById("B1").innerText = document.getElementById("A1").value;
    }
    </script>
    <input id="A1" type="text" value="Enter something here" onClick="value=''">
    <input type="button" value="GO" onClick='process1()'>
    <span id="B1"></span>
    Last edited by h8ids; 05-30-2007 at 07:01 PM. Reason: added code


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •