簡體   English   中英

JavaScript下拉循環if語句

[英]javascript drop down loop if statement

我已經創建了2個下拉菜單,從開始到結束,包括從8> 22:00開始的時間,但是在提交表單時,它要求我選擇一個已經選擇並由警報選項確認的開始時間包括在內,真的讓我感到困惑!! 任何幫助表示贊賞。

克雷格

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

嗯,您的問題之一是在兩個選擇列表上都使用了相同的ID。 給定代碼,很難判斷其余的問題。

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>';  };
     };
<option value='+nb[h]+':'+nb[m]+'>'

只要值不是數字(isNaN),js保存例程就會失敗。 該值中包含一個冒號,因此它永遠不是數字。 您不需要檢查isNaN,因為它是一個下拉菜單,因此您可以控制在那里輸入的內容,這與在文本框中可以使用isNaN來確保用戶輸入數字的文本框不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM