Jump to content

help with form


dadamssg

Recommended Posts

Ive created a form and want to require three fields be filled....and if not an alert comes up. The problem is the alert does come up but as soon as i click ok it still continues to the form action. how do i prevent that? heres the code

 

<?php

/*File: testdisplay.inc
*Display test form
*/
include("sdateselectfun.php");
include("edateselectfun.php");
include("timeselectfuncs.php");
?>


<html>
<head>
<script>
function ValidateFields()
{
    var title = document.getElementById("title");
    var description = document.getElementById("description");
    var location = document.getElementById("location");

    if (title.value == "")
    {
        window.alert("Please enter a Title.");
        title.focus();
        return false;
    }
    
    if (description.value == "")
    {
        window.alert("Please enter a Description.");
        description.focus();
        return false;
    }
    if (location.value == "")
    {
        window.alert("Please enter a Location.");
        location.focus();
        return false;
    }
    return true;
}
</script>
<title>Event Post Form</title>
</head>
<body>
<br><br><center><h2><b>Event Post Form</b></h2></center>



<center>
<form action="checkpost1.php" method="POST" onsubmit="ValidateFields();">
<Table border='7'>
<tr>
<td><center><b>Title:&nbsp</b></center></td>
<td><input type="text" id="title" size="75" maxlength="77"></td>
</tr>
<tr>
<td valign="top"><br><b>&nbspDescription:&nbsp</b></td>
<td><textarea id='description' cols='57' rows='5'>
</textarea></td>
</tr>
<tr>
<td><center><b>Location:&nbsp</b></center></td>
<td><input type="text" id="location" size="75" maxlength="77"></td>
</tr>
<tr>
<td colspan=2>&nbsp</td>
</tr>
<tr>
<td><b><center>Starts:&nbsp</center></b></td><td align=center><?php sdateselect();?>&nbsp&nbsp&nbsp&nbsp<?php stimeselect();?>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
</tr>
<tr>
<td colspan=2>&nbsp</td>
</tr>
<tr>
<td><b><center>Ends:&nbsp</center></b></td><td align=center><?php edateselect();?>&nbsp&nbsp&nbsp&nbsp<?php etimeselect();?>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
</tr>
<tr>
<td colspan=2>&nbsp</td>
</tr>
<tr>
<tr>
<td><center><b>Category:&nbsp</b></center></td>
<td><select name='event'> 
                                <option value='Music'>Music
                                   <option value='Sports'>Sports
                                     <option value='Shows'>Shows
                                        <option value='LocalFestivs'>LocalFestivs
                                          <option value='other'>Other</select>
</td>
</tr>
<input type="hidden" name="do" value="Submit">
<tr>
<td colspan='2' align="center">
<input type="submit" name="do" value="Submit">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/142073-help-with-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.