Jump to content
Sign in to follow this  
Nathan

Form Validation

Recommended Posts

I'm trying to figure out the best way to make sure that the word "delete" was entered into this form field on submit.  If not then it stops and returns something like "you didn't enter the word delete".

<!-- Delete Property Modal -->
<div class="modal fade" id="deletepropertyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">Remove Property</h4>
            </div>
            <div class="modal-body">
                <p>Are you sure you want to delete this property?  If so type the word "delete" in the box below.</p>
                <form role="form">
                    <div class="form-group">
                        <input type="text" class="form-control" id="delete" required>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Delete Property</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

Share this post


Link to post
Share on other sites

Had to add a onsubmit check.

function validate()
{
         if (document.getElementById('delete').innerText != 'delete')
         {
              alert("you didn't enter the word delete");
              return false;
         }
         return true;
}

Share this post


Link to post
Share on other sites

I think you need to close the Input header. Also delete can be all CAPS or only the first D can be caps or all in normal format. Make sure you add all the three variations into your code. Or you can just mention type "delete" as it shown in the text here so that people will understand better.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Sign in to follow this  

×
×
  • Create New...