1 Replies - 1047 Views - Last Post: 16 February 2012 - 01:40 PM

#1 maryjane9110024   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 16-February 12

IsEmpty function for form with multiple search options

Posted 16 February 2012 - 10:21 AM

I have multiple search options on a form with multiple search buttons. When the user hits search I need the validation to fire to check and see if the fields are empty and if so to return false and not submit the information. I am trying to add the IsEmpty function to the current js file.

(The traditional way that I would do this won't work since there are 5 different search options and only 1 form can be on the page.)

Thanks in advance!!

Example: (aspx page)

    <table width="90%">
        <tr>
            <td colspan="7"><b><span class="blue">Parcel Number Search:</span></b></td>
        </tr>
        <tr>
            <td>Book</td>
            <td>Map</td>
            <td>Parcel</td>
            <td>Split</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
                <asp:TextBox runat="server" ID="Book" MaxLength="3" onfocus="this.value=''" 
                    onkeyup="CheckNumericValue(this, 3, event);" Width="50px"/>
            </td>
            <td>
                <asp:TextBox runat="server" ID="Map" MaxLength="2" onfocus="this.value=''" 
                    onkeyup="CheckNumericValue(this,2,event);" Width="50px" />
            </td>
            <td>
                <asp:TextBox runat="server" ID="Parcel" MaxLength="3" onfocus="this.value=''" 
                    onkeyup="CheckNumericValue(this,3,event);" Width="50px" />
            </td>
            <td>
                <asp:TextBox runat="server" ID="Split" MaxLength="1" onfocus="this.value=''" 
                    onkeyup="CheckStringValue(this,1,event);" Width="50px" />
            </td>
            <td>
                <asp:Button ID="Search1" runat="server" Text="Search" onclick="Search1_Click" OnClientClick="IsEmpty()" />
            </td>
            <td>
                <asp:Button ID="ClearParcelSearchButton" runat="server" Text="Clear" OnClientClick="ClearControls('Book','Map', 'Parcel', 'Split');"/>
            </td>
            <td style="width: 900px"><a href="#" onclick="option1()">Help?</a></td>
        </tr>
    </table><br />



Jquery code:

//Validation for Searches

var alphaExp = /^[a-zA-Z]+$/;
var numExp = /^[0-9]+$/;

function IsNumeric(argInput) {
    return argInput.match(numExp);
}

function IsString(argInput) {
    return argInput.match(alphaExp);
}

function CheckNumericValue(argElement, argLength, argEvent) {
    if ($(argElement).val().length == argLength) {
        if (!IsNumeric($(argElement).val())) {
            $(argElement).focus();
            alert("Not a valid number.");
        }
        else {
            autoTab(argElement, argLength, argEvent);
        }
    }
}

function CheckStringValue(argElement, argLength, argEvent) {
    if ($(argElement).val().length == argLength) {
        if (!IsString($(argElement).val())) {
            $(argElement).focus();
            alert("Not a string!");
        }
        else {
            autoTab(argElement, argLength, argEvent);
        }
    }
}

function IsEmpty(argElement, argLength, argEvent) {
    alert("IsEmpty?");
    if ($(argElement).val().length == 0) {
        $(argElement).focus();
        alert("Please enter a value.");
        return false;
    }
    alert("Its Not Empty!");
      
}




Is This A Good Question/Topic? 0
  • +

Replies To: IsEmpty function for form with multiple search options

#2 maryjane9110024   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 16-February 12

Re: IsEmpty function for form with multiple search options

Posted 16 February 2012 - 01:40 PM

Got it!!! And for anyone else who comes upon this thread looking for an answer here it is!

Button Code:

<asp:Button ID="Search1" runat="server" Text="Search" onclick="Search1_Click" OnClientClick="return (!IsEmpty(PageContent_Book) && !IsEmpty(PageContent_Map) && !IsEmpty(PageContent_Parcel))" />


JS code:

function IsEmpty(argElement) {
if ($(argElement).val().length == 0) {
$(argElement).focus();
alert("Please enter a value.");
return true;
}
return false;
}

This post has been edited by JackOfAllTrades: 16 February 2012 - 03:23 PM
Reason for edit:: Added code tags

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1