Maurice
Maurice

Reputation: 1157

Turn my span value into a input value

I have some (javascript) values I want to submit via a form. One of these values I get using a span:

<span id="score_win" style="color:#ffbe5e;">0</span>

This wont submit in a form. So I though, let's convert the javascript output to get it into my input field. I thought this up for the input field:

<input type="text" id="score_win" name="Score" value="0" style="text-align: left; background:transparent; border-style: none; color:#ffbe5e; margin: 0px; font: 14px Arial; width:40px;" readonly />

So far so good, only the value doesn't show now. This is because I haven't edited the javascript part yet. Problem is: how do I do that correctly so that this value can be used in my input field? Since my own attempts failed, I thought asking you guys.

The javascript part:

function foundMatchingBlocks(event, params) {
      params.elements.remove();
      //score += 100;
      score += pointsAvailable;
      $('#score').text(score);
      $('#status2').html('+' + pointsAvailable);
      pointsAvailable = 100;
      $('#score_win').text(score);
};

Kind regards, Maurice

Upvotes: 1

Views: 3602

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038830

Use the .val() function instead of .text() to set the value of an input field:

$('#score_win').val('100');

Upvotes: 2

Related Questions