Newbie, cant get method arguement passed as function parameter to document.write

Hi,
New to JS. Have ordered some new books, but need to get somethings going in the mean time.
What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart.


<script type="text/javascript" >
window.onload=function() {
	document.getElementById("input1").focus();
	}
</script>

So then the wheels came off and in response, began to simplify what was trying to be done to find where the issues were. As far as I can get working is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
	document.getElementById("input1").focus();
	}
</script>
<script type="text/javascript" >
function myFunc() {
alert("is this working");
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc()" maxlength="2" value="type a No." />
</body>
</html>

First issue with this: When I first get to the page everything is just as ordered. The focus is on the text box and the default value is “type a No.” When I press a key onkeyup, I bring up the alert box with “is this working” in it. But when I refresh the page with the refresh button, after clicking the “ok” on the alert box, the character that was typed in is still displayed. If I use the link to the page, or the URL from the address bar, then the page reloads properly with the default value, “type a No”.
Question 1: How do you get the default textbox value using the refresh button as apposed to reloading the page using a link or from the address bar? Using Firefox 8.0

Second and more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I’m doing something wrong on a concept level.
NOTE: changed the default value of the text box to " ". Looked like to me there was an issue with the size specification and the default string length as you could only enter in a key stroke by highlighting the text and replacing it.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
	document.getElementById("input1").focus();
	}
</script>
<script type="text/javascript" >
function myFunc(awe) {
alert(awe);
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc("123")" maxlength="2" value="" />
</body>
</html>
 

Question 2: can someone straighten me out with this?

You can tell Firefox to turn of autocomplete for that field, to prevent that behaviour from occurring.


<input id="input1" ... autocomplete="off" />

Second and more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I’m doing something wrong on a concept level.[/quote]

That problem is to do with the quotes.

onkeyup=“myFunc(“123”)”

To the web browser that looks like you are assigning “myFunc(” to the onkeyup event, which is then followed by 123")" which it doesn’t know what to do with.
You can solve that problem by using single quotes around the 123 instead.