Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 InputFields and 2 Buttons. I would like that when the user clicks the Pi Button or -Pi Button, that value will be assigned to that InputField only where the cursor was (either the first input field or the second).

Button["Range", (DialogInput[{range1 = 0, range2 = 0}, 
Column[{"Enter the Range", 
 Panel[Column[{InputField[Dynamic[range1], Number], 
    InputField[Dynamic[range2], Number], 
    Button["-Pi", (range2 = -3.14159;)], 
    Button["Pi", (range1 = 3.14159;)]}]]}]]), Method -> "Queued"]

Mathematica graphics

share|improve this question

For your usage, you could simply use a PasteButton[] instead.

Button["Range", (DialogInput[{range1 = 0, range2 = 0}, 
Column[{"Enter the Range", 
 Panel[Column[{InputField[Dynamic[range1], Number], 
    InputField[Dynamic[range2], Number], 
    PasteButton["-Pi", -3.14159, Appearance -> Automatic], 
    PasteButton["Pi", 3.14159, Appearance -> Automatic]}]]}]]), 
Method -> "Queued"]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.