i am making some code to make sure the user doesnt input an incorrect month, here is the code i have
function buttonPressed (buttonInstance) {
if (buttonInstance == submitBtn) {
if (yearText.length == 4) {
if (!Number(yearText.text)) {
feedback = "Please input a year in only digits";
return;
}
// check they havent input a year b4 1932
if (yearText.text < 1932) {
feedback = "Please enter a year from 1932 onward.";
return;
}
// also check they havent gone too far in the future
if (yearText.text > myDate.getFullYear()) {
feedback = "Please input a year from 1932 to the current year";
return;
}
// make sure they input a relevant month in combobox
if (monthBox.data > myDate.getMonth()) {
feedback = "Please input the current or previous months";
return; //THIS IS THE PROBLEM IF STATEMENT
}
trace ("Button Pressed");
trace ("______________________________");
// get value of year box
trace (yearText.text);
year = String (parseInt (yearText.text)).substr (yearText.text.length - 2);
trace ("year: " + year);
// get value of month combobox
month = monthBox.getSelectedItem ().data;
trace ("month: " + month);
// get value of date combobox
mydate = dateBox.getSelectedItem ().data;
trace ("date: " + mydate);
// get value of time combobox
time = timeBox.getSelectedIndex ();
trace ("time: " + time);
selectedTime = timeBox.getSelectedIndex ();
trace ("______________________________");
getData ();
} else {
feedback = "Please use 4 figures";
}
}
}
The combobox labels are jan-dec and the data is 01-12
the problem is that if i put an incorrect month it doesnt put out the feedback msg, it just goes straight to the getdata function
Well… I think your problem is the difference between getmonth and your labels. getmonth returns months starting at 0 with January. Your data starts at 1 for January.
You’re obviously familiar with A/S, so here’s a small sample. Good luck.
function onChange(combo1){
mydate=new Date();
thismonth=mydate.getmonth();
monthpicked=combo1.getselecteditem().data;
if((monthpicked+1)>thismonth){
trace("you went too far");
}
}
thank you very much:)
no im not that familiar, ive only been learning 3 months
hope u dont mind if i ask a few more questions if i get stuck?
i will work on what you gave me tomorrow, thanks again
me again, here is what ive been trying but to no avail
function buttonPressed (buttonInstance) {
if (buttonInstance == submitBtn) {
if (yearText.length == 4) {
if (!Number(yearText.text)) {
feedback = "Please input a year in only digits";
return;
}
// check they havent input a year b4 1932
if (yearText.text < 1932) {
feedback = "Please enter a year from 1932 onward.";
return;
}
// also check they havent gone too far in the future
if (yearText.text > myDate.getFullYear()) {
feedback = "Please input a year from 1932 to the current year";
return;
}
trace ("Button Pressed");
trace ("______________________________");
// get value of year box
trace (yearText.text);
year = String (parseInt (yearText.text)).substr (yearText.text.length - 2);
trace ("year: " + year);
// get value of month combobox
month = monthBox.getSelectedItem ().data;
trace ("month: " + month);
// get value of date combobox
mydate = dateBox.getSelectedItem ().data;
trace ("date: " + mydate);
// get value of time combobox
time = timeBox.getSelectedIndex ();
trace ("time: " + time);
selectedTime = timeBox.getSelectedIndex ();
trace ("______________________________");
onChange();
if (onChange().data == true){
getData ();
}
} else {
feedback = "Please use 4 figures";
}
}
}
function onChange(monthBox){
mydate=new Date();
thismonth=mydate.getmonth();
monthpicked=monthBox.getselecteditem().data;
if((monthpicked+1)>thismonth){
trace("Please choose either this or a previous month");
}
}
what im trying to do is call the onChange function when the date has been input, if the month is not in the future then call getData(), it wont work though;(