Using "document.getElementById" to insert form value - is it possible?

I see, learn something new everyday, awesome.

So it should really be more like

<textarea id="myInput4" dmx-bind:value="
'[table]' + (
  form1.preferment.value != '0'
  ? '[tr][td]WOW[/td][td][right]IT HAD A VALUE[/right][/td][/tr]'
  : '[tr][td]WOW[/td][td][right]ITS BLANK[/right][/td][/tr]'
) + '[/table]'" rows="1" cols="2" style="position:absolute; top:0; left:-500px;">
</textarea>

@norcoscia, does this one work?

1 Like

I have been testing - if not converted to a number it works but not when the form is empty. When I convert to a number (below) then it works if zero or not zero or empty - I guess the string must not eval properly when the field is empty (backspaced to nothing in the field). In any case this is now the best Xmas ever - I can make this work. So many thanks to you and Patrick.

Give a man a fish and you feed him for one day - give him Wappler and he can do anything!

<textarea id="myInput1" dmx-bind:value="
'[table]' + (
  form1.preferment.value.toNumber() != 0
  ? '[tr][td]WOW[/td][td][right]IT HAD A VALUE[/right][/td][/tr]'
  : '[tr][td]WOW[/td][td][right]ITS BLANK[/right][/td][/tr]'
) + '[/table]'" rows="1" cols="2" style="position:absolute; top:0; left:-500px;">
</textarea>

Great news, so from there you should be able to adjust as required to get it working. You should not ever really have the input as blank so it should not be an issue, you are just testing if it is NOT 0 which equates to true.

Obviously with your myInput4 example, there was only an if statement and not an if / else, so from your abridged version you gave you would do something like

<textarea id="myInput4" dmx-bind:value="
'[table]' + (
form1.preferment.value.toNumber() != 0
? '[tr]
[td]Preferment (' + (form1.preferment.value) + '%) [/td]
[td][right]' + (form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td]
[td][right]' + ((form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100)) * 0.035274)).round(2) +'[/right][/td]
[/tr]'
) + '[/table]'" rows="1" cols="2" style="position:absolute; top:0; left:-500px;"></textarea>
1 Like

Yes, this solves so many problems for me you have no idea how happy I am. It will take some work and testing but I’m 100% sure I can make it work now.

Even better, I now feel like I understand what is happening and I can control what is handled as text (to be sent to the textarea - the stuff in single quotes) and the things outside of those sets of single quotes are still being evaluated - that is so cool!

I was just kind of knocking this out in total darkness and now I can look at it and some of what I see is starting to register in my brain.

I still don’t know the significance of double quotes but I’m sure in time I will understand that. I want to get to the point that I can look at everything and it all makes sense to me like reading a book in english (for me).

Thanks so much!!!

1 Like

After spending countless hours (OK about 6 hours) trying to get this to work - it will not. There must be something about doing this in the middle of a very large complex textarea that causes dmxAppConnect.js7 Error: Parse Errors but I can’t find it. It seems to work OK when it is in a single small textarea (the abbreviated example) but once moved into the larger real textarea I get parsing errors. I’m stumped and embarrassed to say I need help. I’m out of things to try. I will post the real textarea with the change - the only item I will change are the lines dealing with the preferment. Everything else already works. Below the first code is the preferment section before any changes and it works OK. The next section is the updated textarea with the changes to only copy the preferment line if the value of form1.preferment.value is not equal to zero.

[tr]
[td]Preferment (' + (form1.preferment.value) + '%) [/td][td][right]' + (form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + ((form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100)) * 0.035274)).round(2) +'[/right][/td]
[/tr]
<textarea id="myInput1" dmx-bind:value="'[table]
                                                  [tr]
                                                  [td] [/td][td][b][u]Grams[/u][/b][/td][td][b][u]Ounces[/u][/b][/td]
                                                  [/tr]
[tr]
[td]Total Flour (100%)[/td][td][right]' + (form1.calcweight.value * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (form1.calcweight.value * (1 + (form1.bowlresidue.value / 100)) * 0.035274).round(2) + '[/right][/td]
[/tr]' + (
form1.preferment.value.toNumber() != 0
? '[tr]
[td]Preferment (' + (form1.preferment.value) + '%) [/td][td][right]' + (form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + ((form1.calcpreferment.value * (1 + (form1.bowlresidue.value / 100)) * 0.035274)).round(2) +'[/right][/td]
[/tr]' ) + '                                                 
[tr]
[td]Flour ' + (form1.flour1name.value) + ' (' + (form1.flour1.value) + '%)    [/td][td][right]' + ((form1.calcweight.value * (form1.flour1.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + ((form1.calcweight.value * (form1.flour1.value / 100)) * (1 + (form1.bowlresidue.value / 100)) * 0.035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Water (' + form1.hydration.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.hydration.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + ((form1.calcweight.value * ((form1.hydration.value / 100)) * (1 + (form1.bowlresidue.value / 100))) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Yeast (' + form1.yeast.value + '%) ' + form1.yeasttype.value + '[/td][td][right]' + ((form1.calcweight.value * (form1.yeast.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.yeast.value / 100)) * (1 + (form1.bowlresidue.value / 100))) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Salt (' + form1.salt.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.salt.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.salt.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Oil (' + form1.oil.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.oil.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.oil.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Sugar (' + form1.sugar.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.sugar.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.sugar.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Other ' + form1.item1name.value + ' (' + form1.item1.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.item1.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.item1.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Other ' + form1.item2name.value + ' (' + form1.item2.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.item2.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.item2.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Other ' + form1.item3name.value + ' (' + form1.item3.value + '%)[/td][td][right]' + ((form1.calcweight.value * (form1.item3.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) + '[/right][/td][td][right]' + (((form1.calcweight.value * (form1.item3.value / 100)) * (1 + (form1.bowlresidue.value / 100))).round(2) * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Single Ball [/td][td][right]' + OnceGramValue.value + '[/right][/td][td][right]' + (OnceGramValue.value * .035274).round(2) +'[/right][/td]
[/tr]
[tr]
[td]Sauce TF = ('+ (form1.soz.value / (3.14159265359 * ((form1.pizzasize.value / 2).pow(2)))).round(4) +') [/td][td][right]' + form1.sgr.value + '[/right][/td][td][right]' + form1.soz.value +'[/right][/td]
[/tr]
[tr]
[td]Cheese TF = ('+ (form1.coz.value / (3.14159265359 * ((form1.pizzasize.value / 2).pow(2)))).round(4) +') [/td][td][right]' + form1.cgr.value + '[/right][/td][td][right]' + form1.coz.value +'[/right][/td]
[/tr]
[tr]
[td]Dough TF = (' + (.035274 *((OnceGramValue.value / (3.14159265359 * ((form1.pizzasize.value / 2).pow(2))))).round(4)).round(4) + ')[/td]
[/tr]
[tr]
[td]Number Dough Balls = ' + form1.numberdoughballs.value +' [/td]
[/tr]
[tr]
[td]Pizza Size = ' + form1.pizzasize.value + ' inches[/td]
[/tr]
[tr]
[td]Date Mixed = ' + form1.datemixed.value + '[/td]
[/tr]
[tr]
[td]Date Baked = ' + form1.datebaked.value + '[/td]
[/tr]
[tr]
[td][/td]
[/tr]
[table]
[tr]
[td][b]NOTES: [/b]' + '[/td]
[/tr]
[tr]
[td]' + form1.notes.value + '[/td]
[/tr]
[tr]
[td][/td]
[/tr]
[/table]'" rows="1" cols="2" style="position:absolute; top:0; left:-500px;"></textarea>

can‘t you put the whole thing in a variable and then just call one variable in the textarea?

As I know textarea etc does already escape some stuff like : \n newline \t tabs etc. So thats why maybe putting your stuff into a variable could help… I guess @Teodor knows some solution :ok_hand:t5:

I would be happy to do that if I knew how - the problem I’m trying to solve is that when a user inputs a recipe , depending on the recipe some of the form fields are not used and left at their default value of zero. When the recipe is copied to the clipboard I don’t want to copy the lines for the ingredients that have a zero values. The textarea is pretty big and it is laid out to support BBCode so users can share the recipes on other forums.

Two examples below of the same recipe output, first one is what happens now w/o cutting out lines with zero values, second is what I want it to look like if zeros are in the form fields. Same recipe in both…

2018-12-21_09-17-09

Here a version that uses custom formatters, I hope that I didn’t make some typos.

<textarea id="myInput1" dmx-bind:value="[table]
[tr][td][/td][td][b][u]Grams[/u][/b][/td][td][b][u]Ounces[/u][/b][/td][/tr]
{{form1.preferment.value.row1(form1.calcpreferment.value, form1.bowlresidue.value, 'Preferment')}}
{{form1.flour1.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Flour ' + form1.flour1name.value)}}
{{form1.hydration.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Water')}}
{{form1.yeast.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Yeast', form1.yeasttype.value)}}
{{form1.salt.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Salt')}}
{{form1.oil.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Oil')}}
{{form1.item1.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Other ' + form1.item1name.value)}}
{{form1.item2.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Other ' + form1.item2name.value)}}
{{form1.item3.value.row1(form1.calcweight.value, form1.bowlresidue.value, 'Other ' + form1.item3name.value)}}
[tr][td]Single Ball[/td][td][right]{{OnceGramValue.value}}[/right][/td][td][right]{{(OnceGramValue.value * .035274).round(2)}}[/right][/td][/tr]
{{form1.soz.value.row2(form1.pizzasize.value, 'Souce', form1.sgr.value)}}
{{form1.coz.value.row2(form1.pizzasize.value, 'Cheese', form1.cgr.value)}}
[tr][td]Dough TF = ({{(.035274 * (OnceGramValue.value / (PI * ((form1.pizzasize.value / 2).pow(2))))).round(4)}})[/td][/tr]
[tr][td]Number Dough Balls = {{form1.numberdoughballs.value}}[/td][/tr]
[tr][td]Pizza Size = {{form1.pizzasize.value}} inches[/td][/tr]
{{form1.datemixed.value ? '[tr][td]Date Mixed = ' + form1.datemixed.value + '[/td][/tr]' : ''}}
{{form1.datebaked.value ? '[tr][td]Date Baked = ' + form1.datebaked.value + '[/td][/tr]' : ''}}
{{form1.notes.value ? '[tr][td][b]NOTES:[/b][/td][/tr][tr][td]' + form1.notes.value + '[/td][/tr]' : ''}}
[/table]" rows="1" cols="2" style="position:absolute; top:0; left:-500px;"></textarea>

Here the code for that creates the custom formatters, paste is somewhere below the other script tags in your html.

<script>
  dmx.Formatters('string', {
    row1: function(val, weight, residue, name, type) {
      val = Number(val);
      weight = Number(weight);
      residue = Number(residue);
      
      if (!val) return '';
      
      return '[tr][td]' + name + ' (' + val + '%) ' + (type ? type : '') + '[/td][td][right]' + ((weight * (val / 100)) * (1 + (residue / 100))).toFixed(2) + '[/right][/td][td][right]' + (((weight * (val / 100)) * (1 + (residue / 100))) * .035274).toFixed(2) +'[/right][/td][/tr]';
    },
        
    row2: function(val, pizzasize, name, val2) {
      val = Number(val);
      pizzasize = Number(pizzasize);
          
      if (!val) return '';
          
      return '[tr][tr][td]' + name + ' TF = (' + (val / (Math.PI * ((pizzasize / 2).pow(2)))).toFixed(4) + ')[/td][td][right]' + val2 + '[/right][/td][td][right]' + val + '[/right][/td][/tr]';
    }
  });
</script>
3 Likes

Wow, wow, wow - thanks so much - can’t wait to try this!!!

It all works, I do get one error (below) but it is unbelievable to me that you could do that and have it work so well. I can’t imagine I could do that with months of trying so thank you from the bottom of my heart. I hope I can look at what you have done and learn something. I’m really in awe :star_struck:

2018-12-21_14-51-01

Once I saved, the error cleared, I was having some problems with one of the calculations returning infinity but replacing “PI” with “3.14159265359” fixed it (see below).

[tr][td]Dough TF = ({{      (.035274 * (OnceGramValue.value / (PI * ((form1.pizzasize.value / 2).pow(2))))).round(4)     }})[/td][/tr]
td]Dough TF = (' + (.035274 *((OnceGramValue.value / (3.14159265359 * ((form1.pizzasize.value / 2).pow(2))))).round(4)).round(4) + ')[/td]

This will keep me busy learning - thanks again for the best present ever Patrick :christmas_tree::christmas_tree::christmas_tree: