Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    I'll be back

    gotta go to work, I'll try again later *sighs of frustration*
    Janice Paul

  2. #17
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    These examples ought to point you the right way:-

    Code:
    <form>
    The Date <input type = "text" id = "date"><br>
    Quantity 1<input type = "text" id = "qty1"><br>
    </form>
    
    <script type = "text/javascript">
    
    window.onload = initForm;
    
    function todayTxt() {
    var Today = new Date();
    return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
    }
    
    function initForm() {
    document.getElementById("date").value = todayTxt();  // address element by id
    document.getElementById("qty1").focus();
    }
    </script>
    Or

    Code:
    <form>
    The Date <input type = "text" name= "date" id = "date"><br>
    Quantity 1<input type = "text" name = "qty1" id = "qty1"><br>
    </form>
    
    <script type = "text/javascript">
    
    window.onload = initForm;
    
    function todayTxt() {
    var Today = new Date();
    return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
    }
    
    function initForm() {
    document.forms[0].date.value = todayTxt();   // address element by name
    document.forms[0].qty1.focus();
    }
    </script>
    Or, most correctly, assign the id "myform" to the form and then

    Code:
    function initForm() {
    document.getElementById('myform').date.value = todayTxt(); // address form by id, form element by name
    document.getElementById("myform").qty1.focus();
    }

    var document orders // the name of a variable may not contain a space.
    Last edited by Philip M; 03-10-2012 at 05:39 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #18
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Is this not what you are talking about?
    Code:
    <body>
    <form id="orders" method="post" action="done.htm">
    
       <div id="links">
          <a href="#" class="newgroup">Home Page</a>
    By using the second suggestion of yours I got the current date and the focus to appear. I'll be back later to put what little I have online where we can both see my mess. I don't understand why using the different syntax worked. still, but I DO NOT GIVE UP!
    Last edited by jdpaul; 03-11-2012 at 08:06 PM. Reason: progress w/ the problem I am working on
    Janice Paul

  4. #19
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Smile Online and making slow progress...

    I have gotten the focus and select to work I think. When you first see the page loaded the first field for a quantity of GoMap 1.0 has the edge lit up and the blue on the number in Google Chrome only, I guess I need to learn more CSS to get the golden border to show in Firefox and IE(and I probly need to save that for my time & get the rest of this dang form to work right first. Before I tackle the next piece of code to be added would you please look at this: My Web Form After dinner I guess I will tackle the productCosts function. *sigh* This stuff is a lot harder than HTML and CSS!
    “Dream as if you'll live forever, live as if you'll die today.”
    Albert Einstein
    I love some of the things he said.
    Janice Paul

  5. #20
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question Someone help me figure out where this code is buggy please!

    I have redone this javascript three times now, but it still only gives me the focus and the select ... it is supposed to add the cost amount when you put in a number in the quantity and hit tab ... Firebug tells me nothing. Any suggestions would be greatly appreciated. Janice's Form
    Janice Paul

  6. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    As Philip kept telling you, you can't use the code
    Code:
    document.orders
    unless you have a <form> with that name.

    You do *NOT* have such. You have a <form> with that ID!

    You could fix this part by changing to
    Code:
    <form name="orders" method="post" action="done.htm">
    But form names are considered obsolescent, anyway. So better to leave the <form> tag as you have it and simply change to using
    Code:
    document.getElementById("orders")
    I would suggest this:
    Code:
    function initForm() {
       var form = document.getElementById("orders");
       form.date.value = todayTxt();
       form.qty1.focus();
       form.qty1.select();
    }
    ************

    You do have another problem, though. You can't use method="post" if the action= of a <form> is another HTML page. You can only use method="post" when the target action is a server-side page (e.g., a PHP or ASP or JSP or CGI page).

    Now, if your <form> will never actually be submitted to the action page (which may well be the case for this page you are working on), then the method won't matter. But as a matter of good practice, if you are going to specify action="done.htm" then you should also specify method="get"
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. Users who have thanked Old Pedant for this post:

    jdpaul (03-19-2012)

  8. #22
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The links to your form return 404 errors. Please do try to make it a little easier for us to help you!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  9. #23
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    The correct URL is this:
    http://web-students.pstcc.edu/web230...les/order.html

    Looks to me like it is all working correctly, now.

    No?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  10. #24
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    But, as I told you, your SUBMIT button doesn't work because of the method="post"

    WHen you get to the "done.html" page, you get a 405 error, which says this:
    HTTP Error 405 - The HTTP verb used to access this page is not allowed.
    The "verb" in question is "post" (instead of "get"). HTML is not allowed to process "post" requests.

    Okay?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  11. #25
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Whoops...I take it back: Your form validation isn't complete. You allow an order to be submitted even if no items are ordered.

    Easy fix: If the sales tax is zero, then no items were ordered.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. #26
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Smile just that one little nudge did it!!!


    All I needed was a nudge in the right direction. Awesome dude!!! I did not write the html form the way it was .. but when I changed the wording like you suggested it works fine now. I pray when I go home to put it online live it will continue to behave.
    Thanks so much,
    Janice Paul

  13. #27
    New Coder
    Join Date
    Feb 2012
    Location
    East Tennessee
    Posts
    56
    Thanks
    7
    Thanked 0 Times in 0 Posts

    form done!

    Phillip, I apologize for not seeing your posts! I was under the weather this last weekend. I did not write the form and the way they did the method and the submission part. I really am not sure how it ended up this way. Thanks to your guidance and Old Pedant's I have successfully gotten the form to do what was asked of me. THANK GOD! I thought these people were supposed to know something when they published a book! Hmm, I am not amused with their mess-ups. But, I don't give in and I WILL learn JavaScript one way or the other. Thanks so much for your patience as I struggle with a crumby book and no help outside here.
    Janice Paul


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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