...

View Full Version : Input to auto write



h8ids
05-14-2007, 09:40 PM
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.)

<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">

rwedge
05-14-2007, 10:40 PM
Here is an example of one method:
<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

h8ids
05-15-2007, 02:26 PM
Thank you. I'd been trying the "write" command too but found it didn't do what I'd hoped. (Much like the reload.)

:)

Khaled
05-15-2007, 02:41 PM
Welcome everybody...
I think this is your needs.


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

h8ids
05-30-2007, 05:57 PM
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:


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum