Skip to main content
Inspiring
May 12, 2011
Question

Test to see if text in text box starts with a C

  • May 12, 2011
  • 1 reply
  • 2500 views

I have a text box called Part_Number. If the part number starts with a "C", then I want my Validation_Qty text box be a requirement to be filled in. If there's anything else in the Part_Number box, nothing else matters. There are no requirements for any other part numbers. How would I go about dong this? Here are my 2 text boxes:

<input type="text" name="Part_Number" size="30">

<input type="text" name="Validation_Qty" size="12" validate="integer" required="no" message="You must enter a valid number in the Validation Quantity field">

Thanks.

Andy

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 12, 2011

    Assuming that you want to use CFFORM / CFINPUT validation; you can create your own JavaScript to perform your custom validation and include it using the onValidate attribute of CFINPUT.

    Inspiring
    May 12, 2011

    Bob,

       I added this javascript to my page, but this only stops the page from adding if the Validation Qty. box is not filled in at all. It does not worry if the part number box starts with a C or not. How do I do a wildcard in Javascript that says if the Part number starts with a C, then only require that the Validation Qty. be filled in then? I thought this would work: /C^$/  but it doesn't.

    <SCRIPT LANGUAGE="JavaScript">


    function verify() {
    var themessage = "Please enter ";
    if (document.AddItem.Part_Number.value !== /C^$/ && document.AddItem.Validation_Qty.value == "") {
    themessage = themessage + "Validation Qty.";
    }

    if (themessage == "Please enter ") {
    document.AddItem.submit();
    }
    else {
    alert(themessage);
    return false;
       }
      
    }

    </script>

    Andy

    ilssac
    Inspiring
    May 13, 2011

    When I was in that situation, I bought the book, Teach Yourself Javascript in 24 Hours and did every tutorial.  It met my needs.

    I also know that webmonkey.com has some javascript tutorials.  Not having taken them, I have no opinion of them.


    Dan Bracuk wrote:

    I also know that webmonkey.com has some javascript tutorials.  Not having taken them, I have no opinion of them.

    I did use the webmonkey tutorials back in the day (~2000) and found them to be very helpful.