Thank you. I works fine.
RabbitTrail
Posts
-
focus() not working -
focus() not workingThank you for pointing out my mistakes. I modified my code to include your corrections but the focus still does not put the cursor in the blank text or textarea continters. Any other suggestions? I have tried the code in IE, Firefox and Chrome.
-
focus() not workingBelow is code I have been trying. Everything works except the focus. When the alert box's OK is clicked, focus is not set to the blank text/textarea control that caused the error to happen. According to articles online, this should work but it is not. Any suggestions would be greatly appreciated.
Trying It Out
function checkForm()
{
var str = ''; //for testing purposes later
var e = document.getElementById('myForm').elements;//Insert for statement here// for(i=0; i <= e; i++){ if(e\[i\].value.length <1){ alert("The field " + e.\[i\].name + " is blank"); var mytext = document.getElementById(e\[i\].name) mytext.focus(); return false; } } }
Your Name:
Interesting Fact About You:
something about you
-
Trying to compare cancel from prompt dialog not workingBelow I have the code I am working with. The if statement in the script is not working. What I want to do is catch the value of the prompt dialog box if the user clicks the cancel buttom and exit the script if that is the case. I have tried: if (color=="null") if (color==="null") if (color=='null') if (color==='null') if (color==null) if (color===null) and none of them work. I can make the script work if I do: if(color!=null) and modify the logical processing but I am trying to make work with the equals comparison. If I comment out the if conditional statement, it works fine. Any help is greatly appreciated. Thank you.
<!--
var color = prompt("Enter a color","Enter red, white, or blue.")function colorTest(){
//\*\*\*\*\*\*\*\*\*\* if statement not working properly if(color === null){ break; } switch(color){ case "red": alert("You have entered the color ' red '"); break; case "white": alert("You have entered the color ' white '"); break; case("blue"): alert("You have entered the color ' blue '"); break; default: alert("You did not enter a valid color"); }
}//end function
//-->
-
body onunloadI have been trying to get the method to work. I have seen and tried quite a few online examples including the example found on W3C (which is below). Even on their site, it doesn't work. I have tried to get the method to work by: Refresh the page, using back and forward buttons, and closing the window. Nothing happens in IE, Firefox or Chrome. I am at a loss as to why this doesn't work.
<html>
<head>
<script>
function myFunction()
{
alert("Thank you for visiting W3Schools!");
}
</script>
</head><body onunload="myFunction()">
Welcome to my Home Page
Close this window or press F5 to reload the page.
</body>
</html>