0

I have created 2 drop down menus, from and to, these include times starting from 8 > 22:00, however on submitting the form it is asking me to select a start time which has already been selected and confirmed by an alert option i have included, has really confused me!! any help appreciated.

craig

window.status='Loading contingency scripts - please wait...';
audit('Loading contingency scripts');
var conting={ i:0

,start:function(){
window.status='Loading form - please wait...';
var t='';
t+='<form name="frm_conting" id="frm_conting" onsubmit="return false;">';
t+='<table width="100%" cellspacing="1" cellpadding="0">';
t+='<tr><td>Date (DD/MM/YY):</td><td><input type="text" size="8" value="'+current_date+'" id="date"></td></tr>';

t+='<tr><td>Time Started:</td><td><select id="timefrom"><option></option>';
  for(h=8;h<23;h++){  
      for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };
t+='</select></td></tr>';

t+='<tr><td>Time Finished:</td><td><select id="timefrom"><option></option>';
  for(h=8;h<23;h++){  
  for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };

t+='</select><tr><td>Extension #:</td><td><input type="text" size="5" value="'+my.extension+'" id="staffid"></td></tr>';
t+='<tr><td>Desk ID:</td><td><input type="text" size="5" value='+my.deskid+' id="desk"></td></tr>';
t+='<tr><td>Number of calls:</td><td><input type="text" size="5" id="calls"></td></tr>';
t+='<tr><td>Avid ID:</td><td><input type="text" size="5" id="avid"></td></tr>';
t+='<tr><td><input type="button" value="Submit" onClick="conting.save()"></td>'; 
t+='</table>';
t+='</form>';

div_form.innerHTML=t;  
window.resizeTo(400,385);
window.status='';
}


,save:function(){
 alert (frm_conting.timefrom.value);
  var conting_date=frm_conting.date.value; 
   if(!isdate(conting_date)){alert("You have entered an incorrect date.");return false;};

var conting_timefrom=frm_conting.timefrom.value;  
 if(isNaN(conting_timefrom)){alert("You need to enter a starting time.");return false;}; 
 if(conting_timefrom.value>conting_timeto.value){alert("The time you have entered is after the finish time.");return false;}; 

var conting_timeto=frm_conting.timeto.value; 
 if(isNaN(conting_timeto)){alert("You need to enter a finishing time.");return false;}; 
 if(conting_timeto.value<conting_timefrom.value){alert("The time you have entered is after the finish time.");return false;}; 

var conting_staffid=frm_conting.staffid.value; 
 if(conting_staffid.length!=5) { alert("You have entered an incorrect extension number.");return false;};

var conting_desk=frm_conting.desk.value; 
 if(conting_desk.length!=5) { alert("You have entered an incorrect desk ID.");return false;}; 

var conting_calls=frm_conting.calls.value; 
 if(isNaN(conting_calls)){alert("You have not entered amount of calls.");return false;};

var conting_avid=frm_conting.avid.value; 
 if(isNaN(conting_avid)){alert("You have entered an incorrect avid ID.");return false;};
 if(conting_avid.length!=5) { alert("You have entered an incorrect avid ID.");return false;}; 

 conn.open(db["contingency"]);
 rs.open("SELECT MAX(prac_id) FROM practice",conn);
var prac_id=rs.fields(0).value+1;
 rs.close();
 rs.open("INSERT INTO practice (prac_id, prac_staffid, prac_date, prac_timefrom, prac_timeto, prac_extension, prac_desk, prac_calls, prac_avid) VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9)",conn); 
 conn.close();



}


};
 window.status='';

enter code here
2
  • don't you think you should start with "I have two drop downs, one called start_time and another called end_time..."? Commented Sep 16, 2010 at 12:37
  • yes i should of done really, sorry. Commented Sep 16, 2010 at 12:38

2 Answers 2

1

Well one of your problems is that you're using the same ID on both select lists. It's hard to judge the rest of the problems given the code.

t+='<tr><td>Time Started:</td><td><select id="timefrom"><option></option>';
  for(h=8;h<23;h++){  
      for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };
t+='</select></td></tr>';

t+='<tr><td>Time Finished:</td><td><select id="timefrom"><option></option>';
  for(h=8;h<23;h++){  
  for(m=0;m<46;m=m+15){  t+='<option value='+nb[h]+':'+nb[m]+'>'+nb[h]+':'+nb[m]+'</option>';  };
     };
Sign up to request clarification or add additional context in comments.

1 Comment

that has sorted the problem of the form knowing which time has been selected which the alert i added to brainstorm the fault has said. so thanks for that!! however the problem is now the code comes back saying you need to enter a starting time, which has already been done... confusing
0
<option value='+nb[h]+':'+nb[m]+'>'

The js save routine will fail whenever the value is not a number (isNaN). The value has a colon in it, hence it's never a number. You don't need to check isNaN, because it's a drop down, so you control what is entered there, unlike a text box where you might use isNaN to be sure the user typed in a number.

2 Comments

thanks its a good point, so how would i compare the two drop downs to make sure for example 08:00 is a finish time and 22:00 is a start time returns as false?
pull out the hour and minute portions and compare them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.