Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try stopping the submit event thoroughly (you're suffering from <a href="http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/" rel="nofollow noreferrer">jQuery-itis</a>, causing you to abuse <code>return false</code>):</p> <pre><code>method="post" onsubmit="return validation(event);"&gt; </code></pre> <p>And in JS:</p> <pre><code>function validation(e) { //your checks if (isDataValid === false) { if (e.preventDefault) { e.preventDefault(); e.stopPropagation();//VERY important } e.returnValue = false; e.cancelBubble = true; } return isDataValid; } </code></pre> <p>To find out what both methods do, have a look at what <a href="https://developer.mozilla.org/en-US/docs/DOM/event.stopPropagation" rel="nofollow noreferrer">MDN</a> has to say<Br/> To find out <em>what</em> you're stopping when calling <code>stopPropagation</code> (or setting <code>cancelBubble</code> to <code>true</code>) I'd recommend <a href="http://www.quirksmode.org/js/events_order.html" rel="nofollow noreferrer">quirksmode: events order</a> very easy to follow, reasonably comprehensive description, and, in case you need it: <a href="http://www.quirksmode.org/js/introevents.html" rel="nofollow noreferrer">their introduction to JS events, too</a>.</p> <p><em>Update</em><Br> In response to your comments:</p> <pre><code>&lt;?php // connect to the database include('connect.php'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); die(); } $sql = "SELECT CourseId, CourseNo, CourseName FROM Course ORDER BY CourseId"; $sqlstmt=$mysqli-&gt;prepare($sql); $sqlstmt-&gt;execute(); $sqlstmt-&gt;bind_result($dbCourseId, $dbCourseNo, $dbCourseName); $courses = array(); // easier if you don't use generic names for data $courseHTML = ""; $courseHTML .= '&lt;input type="text" name="courses" id="coursesDrop" /&gt;' . PHP_EOL; $pHTML = '&amp;nbsp;';//default paragraph inner if (isset($_POST['moduleSubmit'])) { $sessionquery = " SELECT SessionId, SessionName, SessionDate, SessionTime, CourseId, SessionActive FROM Session WHERE (CourseId = ? AND SessionActive = ?) ORDER BY SessionName "; $active = 1; $sessionqrystmt=$mysqli-&gt;prepare($sessionquery); // You only need to call bind_param once $sessionqrystmt-&gt;bind_param("si",$course, $active); // get result and assign variables (prefix with db) $sessionqrystmt-&gt;execute(); $sessionqrystmt-&gt;bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbCourseId, $dbSessionActive); $sessionqrystmt-&gt;store_result(); $sessionnum = $sessionqrystmt-&gt;num_rows(); if($sessionnum == 0) {//error msg? $pHTML = "&lt;span style='color: red'&gt;Sorry, You have No Assessments under this Module&lt;/span&gt;"; } } ?&gt; &lt;p id="warnings"&gt;&lt;?php echo $pHTML;?&gt;&lt;/p&gt;&lt;!-- echo the innerHTML created server-side --&gt; &lt;form id="myForm" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post" onsubmit="return validation(event);"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Course: &lt;?php echo $courseHTML; ?&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;p&gt; &lt;input id="moduleSubmit" type="submit" value="Submit Course and Module" name="moduleSubmit" /&gt; &lt;/p&gt; &lt;div id="moduleAlert"&gt;&lt;/div&gt; &lt;div id="targetdiv"&gt;&lt;/div&gt; &lt;/form&gt; </code></pre> <p>Tweaked JS - since you're using jQuery, I'll use that as <a href="https://stackoverflow.com/questions/11331203/javascript-how-to-simulate-change-event-in-internet-explorer-delegation">delegating a change event in IE is a pain</a>:</p> <pre><code>$('#myForm').delegate('change','select',function() { $('#warnings').html('');//clears current warnings }); </code></pre> <p>Or, a more efficient but somewhat more complex take:</p> <pre><code>$('#myForm').delegate('change','select',(function(warnings) { return function() { warnings.html(''); }; }($('#warnings')))); </code></pre> <p>Don't forget to wrap this in a <code>$(document).ready(function(){[here]});</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COOk this has worked but just got one little issue. If I select a course and and module from drop down menu and submit, if that module does not contain any assessments, then it does the php validation which displays the message `Sorry, You have No Assessments under this Module`. This is fine. But if I then straight away do not select a Course from the drop down menu, it displays both the javascript message `Please Select a Course from the course drop down menu` BUT it also still displays the php message. It should remove that php message.
      singulars
    2. COI have an app [here](http://helios.hud.ac.uk/u0867587/Mobile_app/editsessionadmin.php), on the app please select course `INFO101....` and Module `CHT2220....` then submit, you will see the php validation message in red, now the Course and Module drop down menu goes back to saying `Please Select` so straight away click on the same Submitbutton again, then you will see both validation messages appear in red, it should only display the javascript error message `Please select a Course and Module from the Drop down menus above`
      singulars
    3. CO@user1830984: change `echo "<p><span style='color: red'>Sorry,...` to `echo "<p id='invalid'><span style='color: red'>Sorry,..` and create an event listener that listens for a `change` event, the handler should look lik `function(e){ if (document.getElementById('invalid')){ document.getElementById('invalid').innerHTML = "";}};`, this clears the warning once an element is changed
      singulars
 

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