Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

Here is my Aspx page
XML
<form id="FindItems" method="post" action="">
      <input type="hidden" id="FormAction" name="FormAction" value="" />
      <input type="hidden" name="SearchValue" value="<asp:Literal ID='litSearchValue' runat="'server'" />" </form>
       Department:
      <select name="Dept">
<asp:Literal ID="litDeptOptions" runat="server" />
      </select>
     Product Code:

       <input type="text" name="txtVpPrdCd" maxlength="15" style="text-transform:uppercase;"/>

      <input type="submit" value="Search" onclick="myFunction()" />



Now I want a JavaScript to run when user clicks on submit . saying that user is allowed to enter only either Department or Product Code but not both? How can I do that...
Please help me in this
Posted

1 solution

Check this solution.... I took a button click function and add an id to the Drop Down List.
JavaScript
$( "#btnSelect" ).click(function() {
    var ddl = $("#id1 option:selected").val();
    //alert(ddl);

    var text = $("#txt1").val();
    //alert(text);
    var final;

    if(ddl=='0' && text=='')
    {
        alert('Select any one !');
        return;
    }
    else if(ddl!='0' && text!='')
    {
        alert('You have to select only one !');
        return;
    }
    else
    {
        if(ddl!='0') { final = ddl;}
        else if (text !='') {final = text}
    }
    alert('Final Value is ' + final);
});


For on line trial go to JSFiddle [^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900