CF Exists tag? Or Javascript function to check existence of value?

Discussion in 'Programming' started by thequi1ter, May 15, 2009.

  1. #1
    Hello,

    Does anyone have simple syntax that I can use to check to see if a value exists in a SQL Server db table BEFORE the user hits the submit button?

    I have a table that has values in it like this:
    1-apples
    2-oranges
    3-bananas
    4-pears

    If the users want to add another value to this table, I don't want them to try to add 1-apple again. Is there a way to check for the existence of table values before they try to enter a new one - even though it may be spelled slightly differently?

    Obviously my example is a simplified version of my real table. The problem is users cannot be relied upon to check the table carefully before they add a new value. So I have to have some way to check for records that are LIKE what they're trying to add; otherwise the data will end up with 1-apples and 1-apple and possibly 1-aple. Need to protect them from that kind of stuff. Thanks for anyone who can make a recommendation!
     
    thequi1ter, May 15, 2009 IP
  2. thequi1ter

    thequi1ter Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Solution:
    First I wrote a simple query to get the value that the user is trying to add.

    Then I found this javascript;
    <cfif #getExisting.product_ID # eq #form.product_ID#>
    <Script language="JavaScript">
    <!--
    alert("The product_ID you entered is already being used. Please enter another product ID.");
    history.back();
    // -->
    </script>
    <cfelse>
    IF the product_ID is not already in the table, I run an insert query and show the user a thank you page. If not they see the nice alert message (from above).
     
    thequi1ter, May 15, 2009 IP