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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.