Results 1 to 4 of 4

Thread: Dynamic JavaScript form

  1. #1
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic JavaScript form

    Hello:

    I have a dynamically generated form with multiple users. Each user has two

    For each user I have two radio buttons and a text field.

    John __ Approved __Approved with Errors Comments _____________
    Mary __ Approved __Approved with Errors Comments _____________
    Jim __ Approved __Approved with Errors Comments _____________

    <Submit>

    Each form field is independently named

    Status_0, Status_1, Status_2 for the Approved with errors is value "2"
    Comments_0, Comments_1, Comments_2

    The number of users is variable based on the criteria provided.

    If a user selects "Approved with Errors", I want to require a comment in the text field. If not selected, I want an alert box to appear.

    Any examples or suggestions on how to approach? I'm under a tight deadline.

    Thank you

  2. #2
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    lets see the actual code please

  3. #3
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here's the page, the validation is not working:

    HTML Code:
    <html> 
    <head> 
    <script language="JavaScript" type="text/javascript"> 
    function validateComment(timesheet) 
    { 
      var Status = document.getElementById('Status').value; 
      var Comments = document.getElementById('Comments').value; 
    
    	if(Status=='2' && Comments=='')
      { 
            alert("Please enter a comment for" + document.getElementById('Username').value); 
            return false; 
      } 
    } 
    
    </script> 
    </head> 
    <body> 
    <form name="timesheet" method="GET" action="test.html" onsubmit="return validateComment(this)"> 
      <table border="0" id="timesheet"> 
      <tr> 
        <td>Usernmame</td> 
        <td>DeviceName</td> 
        <td>Comment</td> 
        </tr> 
      <tr> 
        <td><input readonly type="text" name="Username_0" size="25" maxlength="25" value="John" /></td> 
        <td><input type="radio" name="Status_0" id="Status" value="1">Approved <input type="radio" name="radio" id="Status" value="2">Approved with Errors</td>
        <td><input type="text" name="Comments_0" size="25" maxlength="25" value="" /></td> 
      </tr>
      <tr> 
        <td><input readonly type="text" name="Username_1" size="25" maxlength="25" value="Mary" /></td> 
        <td><input type="radio" name="Status_1" id="Status" value="1">Approved <input type="radio" name="radio" id="Status" value="2">Approved with Errors</td>
        <td><input type="text" name="Comments_1" size="25" maxlength="25" value="" /></td> 
      </tr>
      <tr> 
        <td><input readonly type="text" name="Username_2" size="25" maxlength="25" value="Jim" /></td> 
        <td><input type="radio" name="Status_2" id="Status" value="1">Approved <input type="radio" name="radio" id="Status" value="2">Approved with Errors</td>
        <td><input type="text" name="Comments_2" size="25" maxlength="25" value="" /></td> 
      </tr>
      <tr>
        <td colspan="3" align="center"><input type="submit" name="Submit" id="Submit" value="Submit"></td>
      </tr> 
    </table> 
    </form> 
    </body>
    </html>
    Last edited by Snookerman; 08-31-2009 at 07:49 PM.

  4. #4
    Join Date
    May 2008
    Posts
    144
    Thanks
    6
    Thanked 11 Times in 11 Posts

    Default

    try this on one of your comments instead:
    Code:
    <input type="text" name="Comments_0" size="25" maxlength="25" value="" onBlur="if(this.value==''){alert('Please enter a comment')" />

Bookmarks

Posting Permissions

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