Default button and validation of text arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helen2007
    New Member
    • Dec 2007
    • 4

    Default button and validation of text arrays

    Hello

    I have a java server pages with a form on it that has number of text boxes, hidden texts and some other controls (images, etc).

    I have two questions. Could you please help me ?

    1. I would like to make one of the buttons on my form the default, so if user presses enter, this button is clicked. How do I do that?

    2. The name of text boxes on the form are dynamic. So I need to have a javascript that checks the fields of my form according to their type and then gives message if it is empty. What property should I use to indicate the type of control?

    Any tutorials, codes, etc. is extremely appreciated.

    Regards
    Helen
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    could you please post the code you have so far ... so that we may have something to work with?

    kind regards

    Comment

    • helen2007
      New Member
      • Dec 2007
      • 4

      #3
      Originally posted by gits
      hi ...

      could you please post the code you have so far ... so that we may have something to work with?

      kind regards
      Thank you for replying. Unfortunately, I donot have any code regarding these questions yet.

      About my first question, I am not sure if this should be done in JavaScript or it should be done in JavaServer Pages?

      And about the second question, I would like to write a loop that goes through different fields of document and if it is textbox, it will validate it. But I don't know what property and value shows that a control is a text box?

      So if you could just give me some hints, I will write the code myself and in case of problems, I can post it again.

      Thank you
      Helen

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        1. have a look at the keypress events and you could call a javascript-function that submits the form ... have a look here for a start

        2. you could simply use:

        [CODE=javascript]var textboxes = [];
        var input_nodes = document.getEle mentsByTagName( 'input');

        for (var i = 0, node; node = input_nodes[i]; i++) {
        if (node.type == 'text') {
        // we could fill a list
        textboxes.push( node);

        // or even call a validate-function
        validate_func(n ode);
        }
        }[/CODE]
        kind regards

        Comment

        • helen2007
          New Member
          • Dec 2007
          • 4

          #5
          Many thanks for helping :)

          Comment

          Working...