সহায়তা খুঁজুন

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

আরও জানুন

It's keydown event "event.preventDefault()" not worked when i used XMLHttpRequest object with synchronal request.

  • 1 উত্তর
  • 14 এই সমস্যাটি আছে
  • 7 দেখুন
  • শেষ জবাব দ্বারা cash2910

more options

dear all. by the question title, i want to disabled "Tab" key in one input field in HTML page, it's normal worked by :

=========HTML================

<input id="fy" value="" onkeydown="doKeydown(this,event)">

==============================
=========SCRIPT===============

<script> function doKeydown(obj,ev){

   if(ev.keyCode == 9){
      
      if (ev.preventDefault){
           ev.preventDefault();
           ev.stopPropagation();
      }
      
      ev.cancelBubble=true;
      
   }

} </script>

============================

but,when i add XMLHttpRequest with synchronal request in doKeydown function. it's can't worked....

====== <ALL HTML>=======

<meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>FF XMLHttpRequest</title> <script type="text/javascript"> function createXmlHttpObj(){ var _xmlHttp; try { _xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { _xmlHttp = null; } } if (_xmlHttp==null && typeof XMLHttpRequest != 'undefined') { _xmlHttp = new XMLHttpRequest(); } return _xmlHttp; } function transCompany_ajax_codeValue(codeObjAry,containerObjAry,fieldStrAry,ev) { var urlStr = "./test1.asp?transCompanyCode={arg0}"; ajax_codeValue1(codeObjAry ,containerObjAry ,fieldStrAry ,urlStr); } function ajax_codeValue1(codeObjAry,containerObjAry,fieldStrAry,urlStr,callbackFuncName) { var _async = document.getElementById("is_async").checked; for (i=0;i<codeObjAry.length;i++) { urlStr = urlStr.replace("{arg" + i + "}",codeObjAry[i].value); if (codeObjAry[i].value=="") { hasNotInputFlag = false; } } var xmlHttpObj = createXmlHttpObj(); //xmlHttpObj.async = _async; xmlHttpObj.open("get",urlStr, _async); xmlHttpObj.setRequestHeader("Content-Type", "text/xml"); //xmlHttpObj.setRequestHeader("X-Requested-With","XMLHttpRequest"); if(_async){ xmlHttpObj.onreadystatechange = function(){ //console.log("onReadyStateChange"); if (this.readyState == 4) { if (this.status == 200) { returnValueObj = eval("(" + this.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i] , eval("returnValueObj." + fieldStrAry[i])); } } //console.log("load success"); } else{ } } } ; } xmlHttpObj.send(); if(!_async){ var returnValueObj = eval("(" + xmlHttpObj.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i],eval("returnValueObj." + fieldStrAry[i])); } } } } function oncodeChange(){ var obj = document.getElementById("fy") ; var disObj = document.getElementById("uo"); var codeObjAry = new Array(); codeObjAry[0] = obj; var containerObjAry = new Array(); containerObjAry[0] = disObj; var filedAry = new Array(); filedAry[0] = "transCompanyName"; transCompany_ajax_codeValue(codeObjAry,containerObjAry,filedAry); } function setObjShow(obj,showValue) { //when is cell object try{ obj.setValue(showValue?showValue:""); return; }catch(e){ } if (obj.tagName == "INPUT") { obj.value = showValue?showValue:""; } else { obj.innerHTML = showValue?showValue:""; } } function doKeydown(obj,ev){ if(ev.keyCode == 9){ oncodeChange(); if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> async: <input type="checkbox" id="is_async">
<input id="fy" value="" onkeydown="doKeydown(this,event)"> <input id="uo" value="" size="100">


====== </ALL HTML>=======

========<SERVER PAGE USE ASP>===========

<%@ Language=VBScript %> <%response.charset="utf-8"%> <% if trim(request.queryString("transCompanyCode"))="" then

   response.write "{""transCompanyName"":""Can not get name"",""transCompanyCode"":""""}"
   response.end

end if

response.write "{""transCompanyName"":""Name " & trim(request.queryString("transCompanyCode")) &""",""transCompanyCode"":""a""}" %> ========</SERVER PAGE>===========

dear all. by the question title, i want to disabled "Tab" key in one input field in HTML page, it's normal worked by : ===============HTML====================== <input id="fy" value="" onkeydown="doKeydown(this,event)"> ========================================== ===============SCRIPT===================== <script> function doKeydown(obj,ev){ if(ev.keyCode == 9){ if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> ======================================== but,when i add XMLHttpRequest with synchronal request in doKeydown function. it's can't worked.... '''====== <ALL HTML>=======''' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> <title>FF XMLHttpRequest</title> <script type="text/javascript"> function createXmlHttpObj(){ var _xmlHttp; try { _xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { _xmlHttp = null; } } if (_xmlHttp==null && typeof XMLHttpRequest != 'undefined') { _xmlHttp = new XMLHttpRequest(); } return _xmlHttp; } function transCompany_ajax_codeValue(codeObjAry,containerObjAry,fieldStrAry,ev) { var urlStr = "./test1.asp?transCompanyCode={arg0}"; ajax_codeValue1(codeObjAry ,containerObjAry ,fieldStrAry ,urlStr); } function ajax_codeValue1(codeObjAry,containerObjAry,fieldStrAry,urlStr,callbackFuncName) { var _async = document.getElementById("is_async").checked; for (i=0;i<codeObjAry.length;i++) { urlStr = urlStr.replace("{arg" + i + "}",codeObjAry[i].value); if (codeObjAry[i].value=="") { hasNotInputFlag = false; } } var xmlHttpObj = createXmlHttpObj(); //xmlHttpObj.async = _async; xmlHttpObj.open("get",urlStr, _async); xmlHttpObj.setRequestHeader("Content-Type", "text/xml"); //xmlHttpObj.setRequestHeader("X-Requested-With","XMLHttpRequest"); if(_async){ xmlHttpObj.onreadystatechange = function(){ //console.log("onReadyStateChange"); if (this.readyState == 4) { if (this.status == 200) { returnValueObj = eval("(" + this.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i] , eval("returnValueObj." + fieldStrAry[i])); } } //console.log("load success"); } else{ } } } ; } xmlHttpObj.send(); if(!_async){ var returnValueObj = eval("(" + xmlHttpObj.responseText + ")"); for (i=0;i<containerObjAry.length;i++) { if (containerObjAry[i]!=null) { setObjShow(containerObjAry[i],eval("returnValueObj." + fieldStrAry[i])); } } } } function oncodeChange(){ var obj = document.getElementById("fy") ; var disObj = document.getElementById("uo"); var codeObjAry = new Array(); codeObjAry[0] = obj; var containerObjAry = new Array(); containerObjAry[0] = disObj; var filedAry = new Array(); filedAry[0] = "transCompanyName"; transCompany_ajax_codeValue(codeObjAry,containerObjAry,filedAry); } function setObjShow(obj,showValue) { //when is cell object try{ obj.setValue(showValue?showValue:""); return; }catch(e){ } if (obj.tagName == "INPUT") { obj.value = showValue?showValue:""; } else { obj.innerHTML = showValue?showValue:""; } } function doKeydown(obj,ev){ if(ev.keyCode == 9){ oncodeChange(); if (ev.preventDefault){ ev.preventDefault(); ev.stopPropagation(); } ev.cancelBubble=true; } } </script> </head> <body> async: <input type="checkbox" id="is_async"> <br> <input id="fy" value="" onkeydown="doKeydown(this,event)"> <input id="uo" value="" size="100" > </body> </html> '''====== </ALL HTML>=======''' '''========<SERVER PAGE USE ASP>===========''' <%@ Language=VBScript %> <%response.charset="utf-8"%> <% if trim(request.queryString("transCompanyCode"))="" then response.write "{""transCompanyName"":""Can not get name"",""transCompanyCode"":""""}" response.end end if response.write "{""transCompanyName"":""Name " & trim(request.queryString("transCompanyCode")) &""",""transCompanyCode"":""a""}" %> '''========</SERVER PAGE>==========='''

parsec দ্বারা পরিমিত

All Replies (1)

more options

check your other js code ...