#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    6
    Rep Power
    0

    form verification with javascript


    Ok here's the setup: Somebody can enter a Title on this form by either selecting from a drop-down or by entering a custom one in a text box. I need to verify that they did not enter something into both. In the drop-down the first option is blank, so if options[1] is not selected, this means it's populated with something else.

    Code:
    <script language="JavaScript">
    <!--
    function validateForm(form)
    {
    if ((Contact_Position.options[1].selected = false) && (form.Contact_Position2.value != ""))
    { alert ("You may only select one Title");
    return false;
    }
    else
    { return true;
    }
    }
    //-->
    </script>


    Thanks in advance.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    6
    Rep Power
    0
    bump
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Ok here's the setup...around here:

    Don't bump your posts - especially after only two hours (unless you'd like to pay someone for their assistance). All consultation here is free - and unscheduled.

    If you'd like an answer, post the HTML for the form, so we can see exactly what's involved.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    6
    Rep Power
    0
    <CFFORM NAME="myform" METHOD="post" ACTION="Update_Contacts_Handler.cfm" onSubmit="return validateForm(this)">

    ......

    <TR>
    <TD ALIGN="right" BGCOLOR="#deebf7"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-2">Title:</FONT></TD>
    <TD BGCOLOR="#ffffff"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1"><SELECT NAME="Contact_Position">
    <OPTION>&nbsp;</OPTION>
    <CFOUTPUT QUERY="Get_Title">
    <OPTION>#Title#</OPTION>
    </CFOUTPUT>
    </SELECT>&nbsp;&nbsp;OR:</FONT></TD>
    <TD ALIGN="right" BGCOLOR="#deebf7"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-2">Fax:</FONT></TD>
    <TD BGCOLOR="#ffffff"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="3"><INPUT TYPE="Text" NAME="Fax_Number" Size="10" MAXLENGH="14"></FONT></TD>
    </TR>

    ....
  8. #5
  9. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Code:
    function validateForm(oForm) {
         if (oForm.Contact_Position.options[1].selected && oForm.Contact_Position2.value != "") {
             alert("You may only select one Title");
             oForm.Contact_Position.focus();
             return false;
       }
         return true;
    }
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    6
    Rep Power
    0
    Thanks I'll try that. What's funny is the problem seems to be that it's not even recognizing the javascript on the page, no matter what I do it just passes along to the next page.

IMN logo majestic logo threadwatch logo seochat tools logo