Search code examples
javascriptcontrolshtmlcontrols

Access values of fields using form controls in javascript?


I have a form with some text fields(mostly date fields) disabled for a particular user,but has got some value in it.I am not sure whether it is a read-only field. anyway the thing is I want to access the disabled field value to perform some other operation using javascript

Here's the stringified value of the control

{"idbase":"row-4-cell-3","lock":{"vary":0,"fixLock":1,"hidden":"","epmSourced":1},"desc":"Plan_date_ac","name":"date-4-3","lockValue":null,"type":"AC"},

I tried using:

 form[var.control).value

and:

 document.getElementById(controls[var].idbase).innerHTML

neither works for me, it keeps throwing 'undefined'.

Note: only javascript, no jquery please!

tried my best


Solution

  • That's a class. To get class data with Javascript. Used below code

    var x = document.getElementsByClassName("example");
    x.value // to get the x value
    x.innerHTML // to get the content inside the element
    

    Refer: https://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp