f.ismayil Posted April 20, 2011 Share Posted April 20, 2011 I have the following code where I try to check if A, ...., Å checkboxes are checked A2,......, ޴ text field also should be filled. If any of textboxes is not field code user shoul receive please, type text. I am not good in JavaScript and hope someone will help me. I can not find mistake in code. Also what is interesting for is it possible to do the same thing without declaring second array? <script language="JavaScript" type="text/javascript"> <!-- function checkform ( form ) { var letters=new Array("A", "B", "C", "D","E", "F", "G", "H","I", "J", "K", "L", "M", "N", "O", "P","Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z", "Æ", "Ø", "Å"); var letters2=new Array("A2", "B2", "C2", "D2","E2", "F2", "G2", "H2","I2", "J2", "K2", "L2", "M2", "N2", "O2", "P2","Q2", "R2", "S2", "T2","U2", "V2", "W2", "X2", "Y2", "Z2", "޾", "ࡲ", "޴"); // ** START ** for (i=0;i<=29;i++){ if (document.myform.letters.checked == true) && (form.letters2.value == ''){ alert( Please, fill in all required textboxes ); form.A2.focus(); return false ; } } // ** END ** return true ; } //--> </script> Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/ Share on other sites More sharing options...
requinix Posted April 20, 2011 Share Posted April 20, 2011 Try something more like if (document.myform[letters[i]].checked == true) && (form[letters2[i]].value == ''){ Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204153 Share on other sites More sharing options...
f.ismayil Posted April 20, 2011 Author Share Posted April 20, 2011 Tried.Still not working. Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204166 Share on other sites More sharing options...
requinix Posted April 20, 2011 Share Posted April 20, 2011 What's your HTML? Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204185 Share on other sites More sharing options...
f.ismayil Posted April 21, 2011 Author Share Posted April 21, 2011 My code is a bit big. So I will give only the part which is related to our matter. <?php echo "<td>" . "<input type='checkbox' name='A'>" . "<INPUT TYPE=hidden NAME='A1' VALUE='$products_list[0]'><a name='A'>" . $products_list[0] . "</a></td>"; $antall = 'A2'; $enhet = 'A3'; echo "<td>" . "<input type='checkbox' name='B'>" . "<INPUT TYPE=hidden NAME='B1' VALUE='$products_list[0]'><a name='B'>" . $products_list[0] . "</a></td>"; $antall = 'B2'; $enhet = 'B3'; . . . echo "<td>" . "<input type='checkbox' name='Å'>" . "<INPUT TYPE=hidden NAME='޳' VALUE='$products_list[0]'><a name='Å'>" . $products_list[0] . "</a></td>"; $antall = '޴'; $enhet = '޵'; ?> Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204366 Share on other sites More sharing options...
requinix Posted April 21, 2011 Share Posted April 21, 2011 By the way, what does "not working" mean? Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204623 Share on other sites More sharing options...
f.ismayil Posted April 21, 2011 Author Share Posted April 21, 2011 I forgot to put this code: echo "<form method='POST' name='myform' action='oversikt.php' onsubmit='return checkform(this);'>"; echo "<td><center><input type="submit" value="Neste"></center></td> <td><center><input type="reset" value="Reset"></center></td>"; echo "</form>"; So, when I click Next button I should receive a warning dialog box telling "Please, fill in all required textboxes". Now I do not get any message when I click next. Just loades next php file. Link to comment https://forums.phpfreaks.com/topic/234286-working-with-arrays/#findComment-1204667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.