Ojay
Ojay

Reputation: 51

Outputting an input value to a span

I uilt a simple page where a user selects a series of dates via a jquery datepicker (It has to support IE8). There's a botton that executesa function in JS that outputs these values to input boxes in a paragraph. Now this works perfectly, my problem is that the end user will be copying and pasting this info and the textbox lenght is often longer than the date string. I know that i can avoid this mess by using and innerHTML. I have been looking at several examples on this forum but I am not having any luck.

function sayHi(){
  // THIS is WHERE input VARIABLES are set, followed by the OUTPUT
  //this defines the First Week of Sickness Paid Start Date
  var BPCName = document.getElementById("BPCName");
  var OUTBPC = document.getElementById("OUTBPC");
  var name = BPCName.value;
  OUTBPC.value = " " +name+ ""

I essentially want "OUTPBC.value" to go within the span when the function is run. Should this appear as part of the sayHi function?

<script>

document.getElementById("OUTBPC").innerHTML = OUTBPC.value;
</script>

and should my paragraph look like

The Period of paid sickness began on

<span id=OUTBPC> </span>,<pP

Upvotes: 0

Views: 92

Answers (1)

Derek
Derek

Reputation: 3435

You need to set innerHTML not value.

OUTBPC.innerHTML = " " +name+ ""; //replaces OUTBPC.value = " " +name+ "" in sayHi

Upvotes: 2

Related Questions