www.webdeveloper.com
Results 1 to 3 of 3

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

  1. #1
    Join Date
    Dec 2011
    Posts
    6

    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.
    Code:
    <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:

    Code:
    <!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
    Code:
    <!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?

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    1/ - Use a reset button in a form or the
    Code:
    document.getElementById("input1").defaultValue.
    2/ - Your input is twice wrong with quotes (not onkeyup="myFunc("123")" but onkeyup="myFunc('12')" or onkeyup="myFunc(\"12\")") and maxlength="2" for value="123" or nor better "type a No." !
    Code:
    <input id="input1" name="input1" type="text" onkeyup="myFunc(this.value)" value="type a No." />

  3. #3
    Join Date
    Dec 2011
    Posts
    6
    thanks 007Julien,

    1. Will try both approaches.
    2. Yeah... the three characters in a 2 character field thing... right. Duh uh. Did not know about the single verse double quote thing. Going to give that a go and will get back with results.

    Ok, so gave it a go and as you are already aware of it works great! Just like its supposed to.

    How do you mark a thread "solved" here. Still have to work up to getting the original goal, but better to start a new thread as will have different issue.

    Thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles