# Q: Getting math answer box initial text to change whenever checkbox is pressed

Dear Desmos CL folks,

I’m trying to make an activity where students have to type in the correct function for a parabola, with them being able to switch between doing it in intercept form or vertex form.

When they select intercept form, I want the initial latex in the math box to be in that form, e.g. (x-1)(x-2), so that they can tweak the numbers. Similarly, when they select vertex form, I want the initial text to be in that format, e.g. (x-1)^2 + 3

Here is a minimal demo of that part:

The problem is that I can’t figure out how to get that text to switch back and forth. In the example posted above, the default initial selection is intercept form, and (x-1)(x-2) shows up inside the math answer box, as desired. Then, when you click on vertex form, it changes to (x-1)^2 + 3, again as desired. However, when I then click back onto intercept form, the text no longer changes. It stays stuck on vertex form. The demo linked above should show that behaviour (it does for me, at least!).

I’m guessing that this is something to do with initialLatex being something that only gets initialised once, but that doesn’t seem to fit with the fact that it can indeed change from the initial default of (x-1)(x-2) to becoming (x-1)^2 + 3 when the vertex-form button gets pushed. Given that this button-push works, I am puzzled why I can’t get the text to switch back again when the other button gets pushed!

Any help greatly appreciated,

Raj

Initial text is exactly that. Only the initial text/latex. Once something is edited in the input it’s no longer initial and can’t be changed. I’d instead have two separate inputs and conditionally hide/display them.

Thanks, that makes sense. Your suggestion is very helpful of having two separate inputs and conditionally hiding/displaying them. However, I confess that I don’t think I know how to do that in CL.

Do you mean two separate pieces of text that would each, one at a time, be able to show up inside the same math answer box? Or do you mean having two different math answer boxes, each with its own separate initial text, and with only one of those two different boxes being visible at any given moment?

Thanks for your help. Much appreciated!

Raj

I don’t want to speak on behalf of Daniel but I believe that yes, this is what he meant.

You can do this via

hidden: XX.isSelected(2)


or similar. To the user, it’s pretty indistinguishable - it just looks like the initial input is changing by the multiple choice box.

1 Like

initialLatex should remain dynamic until a student edits the math input. I think whats happening here is that the math input is doing some auto-formatting for you (with the exponent?) that is then being identified as current latex ≠ initialLatex which locks in the string.

I was able to replicate using a simplified case and updating your initial latex to:

  when checkbox1.isSelected(1) \left(x-1\right)\left(x-2\right)
otherwise \left(x-1\right)^{2}+3


worked for me

The latter as @pirsquared correctly surmised.