crazysaint Posted July 2, 2009 Share Posted July 2, 2009 the folowing is an extract of a code that i wouild like some help with. i want on submit the code to give a warning that some fields are null and that the user should fill them in. function ref() { var reference; reference=document.myForm.file_ref.value; if (reference=="") { window.prompt('All fields must be filled'); return false; window.focus=document.myForm.file_ref.file_ref; } esle { return true; } } </script> </head> <body> <?pHp include "connection.php"; ?> <div align="center"> <p>DATA CAPTURE INTERFACE </p> </div> <?php mysql_select_db("lands",$connection) or die(mysql_error()); $sql="select file_ref from data_entry order by file_ref desc limit 1"; $result=mysql_query($sql); //$num=mysql_numrows($result); if ($result==0) { $fr="1"; } else { $select=mysql_fetch_array($result); $field=$select['file_ref']; $fr=++$field; } ?> <p> </p> <p> </p> <form id="form1" method="post" action="" onsubmit="return ref()"> Link to comment https://forums.phpfreaks.com/topic/164498-invalid-entry/ Share on other sites More sharing options...
RussellReal Posted July 2, 2009 Share Posted July 2, 2009 function ref() { var e = document.getElementById('form1'); for (i = 0; i < e.childNodes.length; i++) { if (e.childNodes[i].tagName.toLowerCase().match(/(?:input|select|textarea)/)) { if (!e.childNodes[i].value) { alert('Missing Fields'); return false; } } } } Link to comment https://forums.phpfreaks.com/topic/164498-invalid-entry/#findComment-867719 Share on other sites More sharing options...
crazysaint Posted July 2, 2009 Author Share Posted July 2, 2009 RussellReal thanks for the help but am still having a small problem.let me post the entire form that is being affected by the onsubmit code <td><select name="series"> <?php $sql="select * from series"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $val1=$row['series']; ?> <option value="<?php echo $val1; ?>"><?php echo $val1; ?></option> <?php } ?> </select> </td> <td height="33"><input name="file_ref" type="text" value="" size="5" /></td> <td><select name="type"> <?php $sql="select * from file_types"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $val1=$row['type']; ?> <option value="<?php echo $val1; ?>"><?php echo $val1; ?></option> <?php } ?> </select> <input name="subj_ref" type="text" size="30" /></td> <td><select name="file_miss"> <option value="YES">Y</option> <option value="NO" selected="selected">N</option> </select> </td> <td><select name="restore"> <option value="YES">Y</option> <option value="NO" selected="selected">N</option> </select></td> <td><select name="investigate"> <option value="YES">Y</option> <option value="NO" selected="selected">N</option> </select></td> <td><select name="remarks"> <?php $sql="select * from remarks"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $val1=$row['remarks']; ?> <option value="<?php echo $val1; ?>"><?php echo $val1; ?></option> <?php } ?> </select></td> <td><select name="locality"> <?php $sql="select * from locality"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $val1=$row['locality']; ?> <option value="<?php echo $val1; ?>"><?php echo $val1; ?></option> <?php } ?> </select></td> <td><input name="vol_no" type="text" size="5" /></td> </tr> </table> <p> <input name="submit" type="submit" /> <input type="hidden" name="subject_repl" /> <input type="hidden" name="loc_repl" /> Link to comment https://forums.phpfreaks.com/topic/164498-invalid-entry/#findComment-867725 Share on other sites More sharing options...
RussellReal Posted July 2, 2009 Share Posted July 2, 2009 honestly my javascript shoudl work basically on any form >.> Link to comment https://forums.phpfreaks.com/topic/164498-invalid-entry/#findComment-867732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.