Saracoglu Saracoglu - 2 months ago 16
Javascript Question

Viewing [object HTMLInputElement] - JavaScript

I using javascript to extract the value from the SPAN element, then put it in a hidden form field, and then submit the data but why am I getting this result?

<form onsubmit="CDMFOCT()" id="CDMFOCTform">
<div class="CDMFOCT"></div>
<span class="CDMFOCT-span"></span>
<input type="hidden" name="CDMFOCTtimer" id="CDMFOCTtimer" value="not yet defined">
</form>


Javascript:

function CDMFOCT() {
CronSaati = $('.CDMFOCT-span').html();
$("#CDMFOCTtimer").val(CDMFOCTtimer);
$("#CDMFOCTform").submit();
};


Output:

Time: [object HTMLInputElement] will...

Answer

Using JavaScript & jQuery to extract the value of span:

var node = $('.CDMFOCT-span')[0].childNodes[0].nodeValue;

Edit: Or just simply:

var node = $(.CDMFOCT-span).text();

Read more about how to get text node of an element in this link

and now putting it in the hidden form field:

$("input#CDMFOCTtimer").val(node);