another checkbox problem

Hi all!
 I have a check button with (enable/disable). 2nd I have a textfield which can contains a date and also a callendar button which controls the input on the date field. The checkbox is supposed to have a indefinite period state. When the checkbox is checked, and the user wants to click on the calendar an alert message should come.

 Thank you
dlcnetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ksivananthCommented:
btn.addActionListener( new ActionListener(){
  public void actionPerformed( ActionEven ae ){
     if( chk.getModel().isSelected() ) JOPtionPane.showMessageDialog(parentComponent, "Your warning message!", "Title", JOPtionPane.WARNING_MESSAGE )

   //your code here to open and show the calendar!
  }
}) ;
0
Michel PlungjanIT ExpertCommented:
Or if you only want to run in on the client (or if you posted this question in the wrong TA - new to JAVA):

What does the button to open the calendar look like?
If just a form button that uses onClick, change to

<input type="checkbox" name="wholePeriod" onClick="this.form.calendarInputField.disabled=this.checked">Whole period
<br><input type="text" name="calendarInputField">
<input type="button"  onClick="if (this.form.wholePeriod.checked) alert('Please uncheck the checkbox');
else {
showCalendar(); // or whatever your calendar code looks like
}">


Please change the fieldnames appropriately...

Michel
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSoftware engineerCommented:
>> When the checkbox is checked, and the user wants to click on the calendar an alert message should come.
In that case I would simply disable the textfield (containing a date and also a callendar button)
Imo, preventing that a user does something unwanted is always better than let him/her do it and give afterwards a message to say (s)he wasn't allowed to do it.

So,

yourCheckBtn.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e) {
          if (!yourCheckBtn.isSelected())
                return;
          yourTextField.setEnabled(false);
     }
});
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Michel PlungjanIT ExpertCommented:
Is that not more elegantly written as

          yourTextField.setEnabled(yourCheckBtn.isSelected());

?
0
zzynxSoftware engineerCommented:
Yes,

yourCheckBtn.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e) {
          if (!yourCheckBtn.isSelected())
                return;
          yourTextField.setEnabled(false);
     }
});

can be written shorter as:

yourCheckBtn.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e) {
          yourTextField.setEnabled(yourCheckBtn.isSelected());
     }
});

Whether is more elegant or better readable is a matter of taste...
0
zzynxSoftware engineerCommented:
Correction!

Both code snippets need a correction:
yourCheckBtn.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e) {
          if (!yourCheckBtn.isSelected())
                yourTextField.setEnabled(true);  // no return here, 
                                       // since that would mean the textfield never gets enabled again
          else
                yourTextField.setEnabled(false);
     }
});
 
which is indeed probably better written as:
 
yourCheckBtn.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent e) {
          yourTextField.setEnabled(!yourCheckBtn.isSelected());  // the ! was forgotten
     }
});

Open in new window

0
dlcnetAuthor Commented:

 @zzynx and @mplungjan
 Thank you both for the sollutions. initially it was mented for Javascript only but since in the near future it wil be a Java application too I can say I got an answer for both problems. Therefore I splited the points in 2, and gave to mplungian 300 since my solution now was needed for javascript.



 
0
zzynxSoftware engineerCommented:
thanx 4 axxepting
0
Michel PlungjanIT ExpertCommented:
You are welcome

About the not (!) I am used to set items .disabled=true so well spotted
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.