1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to validate multiple textboxes having the same name?

Discussion in 'PHP' started by eniyan_admin, Nov 11, 2009.

  1. #1
    Hi all,

    I want to validate a form having multiple textboxes with samename using javascript to ensure that the user is entering values in all the textboxes before submitting the form. The following is my html code.

    <form method="post" action="addfeedetails.php" name="addfee" id="addfee" onSubmit="return Competetiorsfee();">
             <table align="center" style="font-size:11px" class="tblborder">
             <tr align="center">
                 <td colspan="4" class="logintablehdr">Fee Details</td>
             </tr>
                <tr align="center">
                    <td colspan="2">Center Name
                    <select name="centername" id="centername" style="width:150px;text-align:center">
                    <option value=""> ---SELECT--- </option>
                    </select>
                    </td>
                </tr>
                <tr><td></td></tr>
                <tr><td></td><td>Per Batch</td></tr>
                <tr>
                    <td>ME</td>
                    <td><input type="text" name="me" id="me" size="6"></td>
                </tr>
                <tr><td><hr></td><td><hr></td></tr>
                <tr>
                    <td></td>
                    <td>1Stud2Stud3Stud4Stud5Stud</td>
                </tr>
                <tr>
                    <td>BE</td>
                    <td><input type="text" name="be[]" id="be" size="6"><input type="text" name="be[]" id="be" size="6"><input type="text" name="be[]" id="be" size="6"><input type="text" name="be[]" id="be" size="6"><input type="text" name="be[]" id="be" size="6"></td>
                </tr>
                <tr><td><hr></td><td><hr></td></tr>
                <tr><td></td><td>ProjectProj+CoursIEEE</td></tr>
                <tr>
                    <td>MCA</td>
                    <td><input type="text" name="mca[]" id="mca" size="6"><input type="text" name="mca[]" id="mca" size="6"><input type="text" name="mca[]" id="mca" size="6"></td>
                </tr>
                <tr><td><hr></td><td><hr></td></tr>
                <tr>
                <td></td>
                <td>1Stud 2Stud 3Stud 4Stud 5Stud</td>
                </tr>
                <tr>
                    <td>Diploma - CS</td>
                    <td><input type="text" name="dipcs[]" id="dipcs" size="6"><input type="text" name="dipcs[]" id="dipcs" size="6"><input type="text" name="dipcs[]" id="dipcs" size="6"><input type="text" name="dipcs[]" id="dipcs" size="6"><input type="text" name="dipcs[]" id="dipcs" size="6"></td>
                </tr>
                <tr><td><hr></td><td><hr></td></tr>
                <tr>
                    <td></td>
                    <td>Per Batch</td>
                </tr>
                <tr>
                    <td>Diploma - ECE</td>
                    <td><input type="text" name="dipece" id="dipece" size="6">
                    Branch Name<select name="branchname" id="branchname" style="width:150px;text-align:center">
                    <option value=""> ---SELECT--- </option>
                    <?php
                    $sql = "SELECT * FROM `bchip_branch`";
                    $result = mysql_query($sql);
                    while($data = mysql_fetch_array($result)){
                    ?>
                    <option value="<?php echo $data['branch']; ?>"><?php echo $data['branch']; ?></option>
                    <?php
                    }
                    ?>
                    </select></td>
                </tr>
                <tr><td></td></tr>
                <tr align="center">
                    <td colspan="2"><input type="submit" name="submit" value="Submit"></td>
                </tr>
             </table>
             </form> 
    HTML:
    Could anybody tell me how to validate the above form using Javascript.

    Thank you all.
     
    eniyan_admin, Nov 11, 2009 IP
  2. eniyan_admin

    eniyan_admin Guest

    Messages:
    80
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could anybody tell me, its urgent.
     
    eniyan_admin, Nov 11, 2009 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    following code will give you idea about how to achieve it..

    
    <html>
    <head>
    
    <script type="text/javascript">
    function doValidate(fname)
    {
    	var e = document.getElementsByName(fname);
    	for(var i = 0; i < e.length; i++)
    	{
    		if(e[i].value == "")
    		{
    			alert("Please input values");
    			return;
    		}
    	}
    	alert("all fields have some value");
    }
    </script>
    
    </head>
    
    <body>
    	<input type="text" name="ip[]" value="" />
    	<input type="text" name="ip[]" value="" />
    	<input type="text" name="ip[]" value="" />
    	<input type="button" name="Do" value="Do" onclick="doValidate('ip[]');" />
    </body>
    </html>
    
    HTML:
     
    mastermunj, Nov 11, 2009 IP
  4. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0