2

I can print information out from JavaScript, how can I add the information to textbox

the following code displays information relation to description12 from JavaScript

<h6> Description : </h6>  <span id="Description12"> </span><br />

I am now trying to get the information into textbox

<input name="reportnoss" type="text" id="Description12">

which does not work.

3 Answers 3

1

You can't give two controls on the same page identical IDs - they must be unique.

The ID you give the input text box should be for that control.

You will need to use javascript or jQuery to do this if you must do it client-side.

Something like:

document.getElementById("reportnoss").innerText=document.getElementById("Description12").innerText; would work if you gave the input field the ID reportnoss

Sign up to request clarification or add additional context in comments.

Comments

1

As other answers say, you can't have same id.

<h6> Description : </h6>  <span id="Description12"> </span><br />

<input name="reportnoss" type="text" id="DescriptionTextBox">

Javascript to set the span's text to input text:

document.getElementById("DescriptionTextBox").value=document.getElementById("Description12").innerText;

Note you should use .value and not .innerText for input type="text"

If this is not what you were asking for leave a comment.

Comments

0

First, you cannot have 2 elements in the same document that have the same id. Remove the input's id or change it to another id.

<h6> Description : </h6>  <span id="Description12"> </span><br />
<input name="reportnoss" type="text" id="Input_Description12">

Then, to get the text in the textbox and put it into the span:

var txt = document.querySelector("#Input_Description12").value;  //get the text
document.querySelector("#Description12").innerText = txt;        //put it in

  -and the opposite-

var txt = document.querySelector("#Description12").innerText;
document.querySelector("#Input_Description12").value = txt;

Demo: http://jsfiddle.net/DerekL/bFZMb/

Method used:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.