首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >javascript下拉循环if语句

问javascript下拉循环if语句
EN

Stack Overflow用户
提问于 2010-09-16 20:29:12
回答 2查看 602关注 0票数 0

我已经创建了两个下拉菜单,from和to,其中包括从8> 22:00开始的时间,但是在提交表单时,它要求我选择一个已经由我包含的警报选项选择并确认的开始时间,这真的让我感到困惑!感谢您的帮助。

克雷格

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-09-16 20:42:02

您的问题之一是在两个选择列表上使用相同的ID。根据代码,很难判断其余的问题。

代码语言:javascript
复制
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>';  };
     };
票数 1
EN

Stack Overflow用户

发布于 2010-09-16 21:40:13

代码语言:javascript
复制
<option value='+nb[h]+':'+nb[m]+'>'

只要该值不是数字(isNaN),js保存例程就会失败。值中有一个冒号,因此它永远不是数字。您不需要检查isNaN,因为它是一个下拉列表,所以您可以控制在那里输入的内容,这与文本框不同,在文本框中,您可以使用isNaN来确保用户输入了数字。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3726633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档