Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to validate multiple same type input with same names in javascript
    text
    copied!<p>I am a bit new to Javascript. I have a html form with multiple input types but with the same names occurring multiple types. I need to validate the form before inserting the data in the form into the database. I am able to update and insert into the database without JS validation but am unable to perform the validation part using javascript because of complications with handling inputs with the same names. Here is the form:</p> <pre><code> &lt;form name="confirmation" method="post" action="appointment.php" onsubmit="return check()"&gt; &lt;label&gt;Restaurant Name: &lt;/label&gt; &lt;input name="r_name[]" type="text" value="&lt;?php echo $row[0]?&gt;"&gt;&lt;br&gt; &lt;label&gt;Appointment Date: &lt;/label&gt; &lt;input name="app_date[]" type="date" value="&lt;?php echo $row[1]?&gt;"&gt;&lt;br&gt; Confirm:&lt;select name="confirm[]"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;option value="yes"&gt;Yes&lt;/option&gt; &lt;option value="no"&gt;No&lt;/option&gt; &lt;/select&gt;&lt;br&gt;&lt;br&gt; &lt;/form&gt; </code></pre> <p>Here is the php code to update the database:</p> <pre><code>&lt;?php if(isset($_POST['submit'])){ $names= $_POST['r_name']; $dates=$_POST['app_date']; $confirm=$_POST['confirm']; //echo $count; for($i=0;$i&lt;$count;$i++){ //echo "success"; $value=$confirm[$i]; if($value=="yes") $value="y"; else $value="n"; // echo $value; $result= mysql_query("update appointment set confirm='".$value."' where rname='".$names[$i]."';"); } }?&gt; </code></pre> <p>To insert/update the data with same names in the form into the database I had to associate [] to their respective names for it was the easy way out. But I am having problem assessing it in javascript for the validation part. Could anyone suggest me how to go about doing it with a small code snippet with any of the names used for the input types used in the above form. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload