Form Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hasano
    New Member
    • Feb 2007
    • 3

    Form Problem

    I have this if statement in a form
    Code:
    <cfif #URL.Type# IS "Edit">
    <input type="button" value="Edit message" onClick="validate()" name="Edit">
    <cfelseif #URL.Type# IS "Delete">
    <input type="submit" value="Delete message" name="Delete">
    </cfif>
    where validate() is a javascript function that submits the form.

    Code:
    <script type="text/javascript">
    function validate(){
    document.form.submit();
    }
    </script>
    however, this is not working, i used a submit type button instead of the validate function and it worked, but i need the submission to be done in the javascript function and not as a submit button.

    any suggestion??
    thanks in advance.
    Last edited by acoder; Apr 2 '12, 01:29 PM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Are you sure that the name of your form is "form"?

    Why is it necessary for it to be via Javascript? What if someone has Javascript turned off? It's much safer/better to have a normal submit button.

    Another thing: there's no need to use hashes in cfif statements. You can simply use:
    Code:
    <cfif url.type EQ "Edit">

    Comment

    • hasano
      New Member
      • Feb 2007
      • 3

      #3
      im only submiting in the javascript for testing reasons, but when this works ill have to check whether any of the inputs is empty, if it is then i have to fire an alert message else i will submit the form.
      Do you have any idea how to check a form input if it is empty and thus display a prompt or alert message.???
      Last edited by acoder; Apr 2 '12, 01:30 PM.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        For this, you can still use the submit button, but also include an onsubmit in your form tag:
        Code:
        <form name="form" action="..." onsubmit="return yourErrorCheck();">
        Your error check function will check for errors. If there are any errors it will return false (stopping submit), otherwise return true (the form is submitted).

        To check if a form input is empty, you can use the following code:
        Code:
        if (document.form.inputname.value == "") {
        alert("Please enter a value for blah blah...");
        This is Javascript code, but since you're using Coldfusion, I've answered here.

        If you still have problems, post again.
        Last edited by acoder; Apr 2 '12, 01:30 PM.

        Comment

        Working...