Jump to content

How to pass calculated value from HTML to JS?


Prashant S A
Go to solution Solved by David Boot-Olazabal,

Recommended Posts

Hi,

I am looking to show/hide few elements in text area by using condition.

This value in a condition is available in text area in the form of calculated value.

 

How can I pass above calculated value to JavaScript.

 

Below is the script which I am using(not working),
HTML:

//calculated value(0 or 1 ..)

<pre hidden >
<SpotfireControl id="b1cb3cb958c34edfbd1f8deeb4023e88" />
</pre>

JS:

// Function to show or hide elements based on the input value
function toggleElements(value) {
    let element1 = document.getElementById('93e07d4fcc054f78a00f64d1dfe70556');
 
    if (value = 1) {
element1.style.display = 'block'; // Show element1
    } else {
element1.style.display = 'none'; // Hide element1
    }
}

// Function to check the value from the input field
$('#b1cb3cb958c34edfbd1f8deeb4023e88').on('change',function(){
let inputValue = document.getElementById('b1cb3cb958c34edfbd1f8deeb4023e88').value;
toggleElements(Number(inputValue));
})

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...