Jump to content

Pravin Kumar Raja

  • Posts

  • Joined

  • Last visited

Pravin Kumar Raja's Achievements


Newbie (1/7)



  1. This is in connection with the web page https://www.w3schools.com/js/js_arrays.asp. Array.isArray function does not return correct true when its argument is an array of object. What can be the reason? Is it a bug? A method suggested by W3ishools to use a tailor-made function function isArray(x) { return x.constructor.toString().indexOf("Array") > -1; } which also does not work, as in the code given below: <!DOCTYPE html> <html> <body> <h2>JavaScript Arrays</h2> <p>This "home made" isArray() function returns true when used on an array:</p> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = isArray(document.getElementsByTagName("p")); function isArray(myArray) { return myArray.constructor.toString().indexOf("Array") > -1; } </script> </body> </html> The function returns false. What is a foolproof method to check whether a variable is an array?
  2. I had 2 INPUT boxes and one BUTTON. I want to take the control back to the current INPUT after BUTTON is clicked. That part is working fine with the HTML file shown below: <!DOCTYPE html> <html> <head> <script> var last; function Focus(input) { last = input; } function Blur(input) { } function Click(button) { if (typeof last != "undefined") last.focus(); } </script> </head> <body> <input id="I1" onfocus="Focus(this)" onblur="Blur(this)"> </input> <input id="I2" onfocus="Focus(this)" onblur="Blur(this)"> </input> <button id="B" onclick="Click(this)"> Click </button> <script> </script> </body> </html> But I wanted to code onblur function Blur to incorporate check whether the input is exited with a blank string and to return control to the blank INPUT field after displaying an alert to that effect. This displays the alert box continuously. Can you suggest how this can be avoided. Here is my code: function Focus(input) { if (typeof last != "undefined") if (last.value.length == 0) alert("Blank!"); last = input; }
  • Create New...