How to make div a value

hello how do i make the div below a value so i can submit it

<div id="demo">Display the result here.</div> 


<script>
document.getElementById("demo").innerHTML = ({ALLTOTAL} / {TOTALUSER1} * {TOTAL} > {MIN_BIDS}) ? '<div id="high"></div>' : '<div id="low"></div>';
</script>

thanks

Where do the variables in your script come from? None of them are declared, or have values assigned to them.

div elements don’t have a .value property that would get submitted to the backend; use an input element for that.

Is that some template syntax? Because it isn’t valid JS…

this is the full code i just want to know how to make the div which output the result becomes a value

<div id="demo_score">Display the result here.</div> 
<script>
document.getElementById("demo_score").innerHTML = ({BIDTOTAL} / {TOTALUSER1} * {HOUSE_COMMISSION} > {MIN_BIDS}) ? '<div id="high"></div>' : '<div id="low"></div>';
</script>


<script>
var x = ( {BIDTOTAL} / {TOTALUSER1} ) * {HOUSE_COMMISSION} ;
document.getElementById("high").innerHTML = x;
</script>
    
<script>
var x = {MIN_BIDS} ;
document.getElementById("low").innerHTML = x;
</script> 

thanks

There are no form fields that behave like a div.

What you can do instead is to create a hidden form field, and then update the hidden field.

<form id="scoreform">
    <input type="hidden" name="high">
    <input type="submit>
</form>
document.getElementById("high").innerHTML = x;
var form = document.getElementById("scoreform");
form.elements.high.value = x;

ok will checkem

You should use .value method instead of .innerHTML when adding value to form input element, .value refers to form field value while .innerHTML should be used for inserting HTML in some HTML element.

Also
var form = document.getElementById("#scoreform");
wont work because of hashtag, remove it.

The innerHTML is aimed at his pre-existing div.
The form value is updated via the elements line.

My apologies for the confusion there.

Thanks for the hashtag advice, I’m too used to using querySelector instead.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.