+ 1

Please help me ! Which method I want use in JavaScript?

-------------------------------------------------- Date : 01 - 01 - 23 HTSC No : ### Cust Name : *** -------------------------------------------------- Imp Kwh : 0.00 Imp A : 0.00 Imp B : 0.00 Imp C : 0.00 Imp D : 0.00 Imp E : 0.00 Imp LAG : 0.00 Imp LEAD : 0.00 Imp Kvah : 0.00 Exp kWh : 0.00 Exp A : 0.00 Exp B : 0.00 Exp C. : 0.00 Exp D : 0.00 Exp E : 0.00 Exp LAG : 0.00 Exp LEAD : 0.00 Exp Kvah : 0.00 ======================== Kwh Export : 0.00 LCS : 0.00 Gen. Hrs : 0.00 Hrs Kwh Imp : 0.00 Kvarh Imp : 0.00 % of Kvarh : 0.00 Log : Nill Lull Hours : 00.00 Hrs ______________________________ Any idea to get the values from the given In textarea above . I want to get the values from the given paragraph in textarea to javascript variable to process the values please help me to what method I want to use?

30th Dec 2022, 5:42 PM
Abinesh M
Abinesh M - avatar
2 odpowiedzi
+ 1
There are several ways you can extract the values from the textarea using JavaScript. One way is by using regular expression. You can use a regular expression to find the values in the text area and then assign them to variables. For example: // Create a regular expression to match the values let regex = /Imp Kwh\s*:\s*([0-9.]+)\s*Imp A\s*:\s*([0-9.]+)\s*Imp B\s*:\s*([0-9.]+)\s*Imp C\s*:\s*([0-9.]+)\s*Imp D\s*:\s*([0-9.]+)\s*Imp E\s*:\s*([0-9.]+)\s*Imp LAG\s*:\s*([0-9.]+)\s*Imp LEAD\s*:\s*([0-9.]+)\s*Imp Kvah\s*:\s*([0-9.]+)\s*Exp kWh\s*:\s*([0-9.]+)\s*Exp A\s*:\s*([0-9.]+)\s
30th Dec 2022, 7:17 PM
Muhammed Favas T P
Muhammed Favas T P - avatar
+ 1
If you just need to get value, you need to select elem and use .value() method elem.value() Where elem is your textarea element Here is ways how you can select elem: https://www.educative.io/answers/what-are-the-different-ways-to-select-dom-elements-in-javascript If you need to check data to match some format, you may use regex as Muhammed Favas T P said, but you can also test this string by writing js code. Regex may be hard to understand, but it very powerful skill, here is good testing tool for it, it also have reference - short description how to use regex https://regex101.com/
30th Dec 2022, 9:45 PM
PanicS
PanicS - avatar