Experts,
I wrote a small piece of js/html code like this:
Here are my questions:
1) Is there a difference between onChange="isBlank(this);" and onChange="return isBlank(this);"?
I tried both and could not tell the difference.
2) After I entered something and clicked anywhere on the screen, the js function isBlank() is invoked. Certainly this is not ideal. How can I implement it in a way so that isBlank will be called ONLY when I clicked the button 'Submit'?
3) To solve the question in #2, I tried 'onSubmit' instead of 'onChange'. But it did not work.
However, I do believe 'onChange' is not an ideal way for this purpose, because the current implementation has a problem as follows:
After you enter something, you click once, isBlank() is called. But if you click twice w/o entering a new string, isBlank() will not be called. I understand this behavior is caused by onChange(), because nothing is changed, no need to call isBlank().
So, how do I make sure that isBlank is called whenever I click 'Submit' button with or without make a change in the user input area?
4. I also need help in implementing what is stated inside 'function isBlank()' as a comment in RED.
I hope I have made myself clear and thank you, in advance, for your help.
I wrote a small piece of js/html code like this:
Code:
<head>
<script language="JavaScript" type="text/javascript">
function isBlank (userInput) {
var val = userInput.value;
alert('In isBlank(), val = ' + val); // for debug only
[COLOR=red]/* what I want to do:
if userInput is blank, ask users to enter something
else go ahead to call save.pl
*/[/color]
//return false;
}
</script>
</head>
<body>
<form method="post" action="save.pl" name="theForm">
First Name: <input type="text" name="fname" onChange="isBlank(this);" />
<input type="submit">
</form> </body>
Here are my questions:
1) Is there a difference between onChange="isBlank(this);" and onChange="return isBlank(this);"?
I tried both and could not tell the difference.
2) After I entered something and clicked anywhere on the screen, the js function isBlank() is invoked. Certainly this is not ideal. How can I implement it in a way so that isBlank will be called ONLY when I clicked the button 'Submit'?
3) To solve the question in #2, I tried 'onSubmit' instead of 'onChange'. But it did not work.
However, I do believe 'onChange' is not an ideal way for this purpose, because the current implementation has a problem as follows:
After you enter something, you click once, isBlank() is called. But if you click twice w/o entering a new string, isBlank() will not be called. I understand this behavior is caused by onChange(), because nothing is changed, no need to call isBlank().
So, how do I make sure that isBlank is called whenever I click 'Submit' button with or without make a change in the user input area?
4. I also need help in implementing what is stated inside 'function isBlank()' as a comment in RED.
I hope I have made myself clear and thank you, in advance, for your help.