my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Reset button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Reset button" Watch "Reset button" New topic
Author

Reset button

Peggy Jones
Greenhorn

Joined: Jul 04, 2012
Posts: 19
I have solved all of my other problems I was having with my code. I finally have a working program now. The only thing that I cannot solve is a global reset button. I have search the web and most of the reset commands are not working to reset all of my forms. Does anyone have any suggestions . I do hope that I posted the code correctly thank you.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Why do have multiple reset buttons per form? You only need one per form.

And what's "not working" about them. A reset button should return the form values to those specified by the page markup.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peggy Jones
Greenhorn

Joined: Jul 04, 2012
Posts: 19
The only reset button that is working is the one close to the last form. The reason that I have multiple forms is this was the only way that I could figure out how to do them. I am totally new to Java script and the other one I tried did not work for me. I realize that I only need one reset button, and I cannot get the one and the bottom to work. I have tried search Google for some help but I tried them and they did not work. My original question was did anyone have any suggestions for me to try for just one reset button like I have for the generate button.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Peggy Jones wrote:The reason that I have multiple forms is this was the only way that I could figure out how to do them.

I didn't ask why you had multiple forms -- I asked why you have more than one reset button in a single form.

But after answering that one, why do you have multiples forms?

I am totally new to Java script and the other one I tried did not work for me.

Reset buttons don't have much to do with JavaScript -- they are HTML elements.

Let's clean things up a bit before worrying to much about the reset buttons. Let's start with:

  • Why the multiple forms?
  • Clean up the markup by moving all that repeated style info to the <style> element in the head.
  • Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I have multiple forms to get 6 rows of numbers to show at one time.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Peggy Jones wrote:I have multiple forms to get 6 rows of numbers to show at one time.


    That makes no sense. Why do you feel you need multiple forms for this?
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    Because, I couldn't figure out another way of doing it. Besides, that is what the teacher instructed us to do. He said that was the only way to get more than one row to show. I was only doing what I was instructed to do. I can't argue with him since this is new for me.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    If that's really that he told you, he's an idiot. There's no need for multiple forms just to show multiple "rows". (Since you don't have a table, there aren't any real rows anyways.)

    Well, let's clean it up the best we can. Have you removed all the redundant STYLE attributes? They really mess up the code.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I am working on taking them out now.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    That should clean things up a bit and make it easier to see the structure of the markup. Repost when you are done (UseCodeTags) and we can take it from there, beginning with what you are actually trying to accomplish.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    Okay, I have cleaned it up.

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    OK, now, what are you trying to do with a reset button? The one you have in your markup isn't in a form at all. Your markup is invalid -- you have an end form at line 147 with no opening form.

    There are also nesting problems with your table, row and cell tags. You need to clean those up. Using proper indentation would help see these errors. I strongly suggest indenting your HTML properly.

    If your editor does not show you these problems, find an online HTML validator. Invalid markup will usually cause silent failures that are perplexing.

    I'd also check with your instructor to make sure you understood him/her. The multiple forms are nonsense and I'm just hoping that you misunderstood something. But if you must use multiple forms , what's the behavior you are after?

    Don't show code -- explain clearly what you want to happen.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I really do thank you for all of your help. I am not saying that my teacher is the best, I believe that he was self taught and he likes the c language. He was saying that we needed to know the c language before taking the class. I do not know c and maybe that is why I am struggling so. I have tried searching for some books on the web to better help me with this class. When I was in class on Thursday he said what I had was good and he did not see an easier way of doing the six rows of boxes. This is what he gave us:

    Create a <form> ... </form> to include 6 text boxes as readonly. Include a button

    <form action="" name="name of form">
    <p>
    <! 6 input text boxes here; declare separate names for each >
    <! set up a button here, give it a name and value. >
    <! The onclick routine will call a function to load the lucky numbers into an array. >
    <! ie: onclick="startit()" >
    </p>
    </form>

    Now, he creates his own commands that he wants us to use. I just wanted to do the six rows of six boxes for the numbers and a generate button then I had the bright ideal to add a reset button. I am really only trying to learn the Lagrange. I will go back into my code to check for the errors that you have pointed out.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Peggy Jones wrote:I really do thank you for all of your help.


    That's what we're here for!

    I am not saying that my teacher is the best, I believe that he was self taught and he likes the c language. He was saying that we needed to know the c language before taking the class.

    Hmm. You do not need to know C to learn JavaScript. All languages help to learn other languages, so learning many languages is a good thing, but knowing C is not a prerequisite to JavaScript in any way.

    I do not know c and maybe that is why I am struggling so

    Nope. You're just having the usual learning pains. We were all there once. Is JavaScript your first language?

    he did not see an easier way of doing the six rows of boxes.

    Forms have nothing to do with layout. There could be many reasons to have multiple forms on a page, but layout is not one of them. Perhaps he's just trying to make it easier to keep each row as a discrete submittable entity -- which is what a form creates.

    This is what he gave us:

    OK. I don't see anything in there about multiple rows. Just one row of 6 text inputs.

    Where do the 5 other rows come in?

    Is it perhaps something you've misunderstood? Or are the other rows mentioned in another part of the assignment?

    then I had the bright ideal to add a reset button.


    It's a good idea to get the basic functionality working before adding bells. Let's work on that. Fix up your markup -- make sure to use good indentation, and make sure that all the nesting is correct.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I have corrected all of the html errors except for one. It is saying that I cannot form action within the table. I do not know how to correct this and when I Google it I get no help.

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Peggy Jones wrote:It is saying that I cannot form action within the table

    Please show the relevant code fragment.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    The below code is what will not validate in html. This is the error message: The "form" element cannot be used here. It is contained in a "table" element (which was started in line 52) that cannot contain it. This element may be contained in "body", "dd", "td", and "th". This element may not be contained in "button", "dl", "form", and "table".
    ---




    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    OK, you're going to need to step up to the plate here and act upon the suggestions that are being made.

    Looking at unformatted HTML makes it really hard to see the structure and harder to see where the problems are. Please use consistent and proper indentation. Look at the markup on the first 5 lines. You have the table, the tr, the td and the form all at the same level. This is poor. The tr is inside the table; indent it. The td is inside the tr; indent it. The form is inside the td; indent it.

    For example:

    and so on.

    This makes it easy to see the structure, and also makes it easy to see where you make mistakes in the structure.

    For example: on line 21 you have a form after a </tr>. Does that make sense? No. On lines 33 and 34 you have closing </tr> and </td> that match nothing. Proper indentation would show these problems.

    On line 36 you a <form> that does what? it's just floating in space.

    On line 38 you have a <td> that's not in a <tr>.

    Fix these problems starting with indenting the code properly. This will help reveal any structural issues in your markup, of which there are many. I recommend 2 spaces for each indentation level as shown in my example above.

    Post back when these problems are fixed. Programming is all about attention to detail and precision. You are not showing much of either in this code.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    By the way, you never did answer the question about the 6 rows.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I am sorry. He wants us to show more than one row of numbers, for example: 5,10,6,12,30.45
    10,32,8,45,50,1.
    That is the reason for the six rows. I think the lottery card has where you can play more than one row on a ticket.

    I though that the program I was using automatically formatted the code. I will post again when I have made the corrections. Thank you
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    okay, I have arranged the form in the correct format and the CSE HTML Validator Lite v11.0 said that there were no errors or warnings.

    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    Sorry, my top </form was out of place I did put it back in place.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Here it is properly indented. You only indent things that are inside other things. Siblings go on the same level -- so all the inputs inside the form should be at the same indentation level.

    Study and ask questions if you have any.



    Now, back to the rest button. It's not inside any form so it's not going to have any effect. What is it that you want it to do?
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I want it to reset the whole form. To erase all six rows.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Except that there is no "whole form"... you have six of them. One reset button can only "reset" the form in which it resides.

    So, that's where some JavaScript magic needs to come in.

    Make the button just a regular button, and assign a click handler to it. In the click handler you'll need to get references to each form element and call its reset() method.

    Hint: give each form a unique id, and use document.getElementById() to fetch a reference to each.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I did the reset button and I did the get document.getElementById(), bu the button still does not work. Did I follow your instructions correctly? Here is the total code

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    I see no id values on the forms.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    I added the value on the form

    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    Now you should be able to select by id.
    Peggy Jones
    Greenhorn

    Joined: Jul 04, 2012
    Posts: 19
    Mr. Bibeault,

    I would really like to thank you for all of your help with my project. I have really learned a lot, things that my instructor should be doing. I finally have the reset button to work.

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Reset button