Alert box, Drop down list, Text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shravanti88
    New Member
    • Mar 2010
    • 7

    Alert box, Drop down list, Text box

    How do i display an alert box showing "The value already exists" when an existing option is added to the dropdown list box from a text box?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    please show the code you have so far ... what is the exact problem you have? the existance-check or what?

    kind regards

    Comment

    • shravanti88
      New Member
      • Mar 2010
      • 7

      #3
      Hello,
      The code i have created is as follows.I need to include a statement to display an alert box showing "the value already exists" , when an existing option is added to dropdown list box from a text box.

      Code:
      <html>
      <script type= "text/javascript" language="javascript">
      function addition()
      {
      var textb= document.getElementById("txtCombo");
      var combo= document.getElementById("combo");
      var option= document.createElement("option");
      option.text= textb.value;
      option.value= textb.value;
      combo.add(option);
      }
      </script>
      <body>
      <form>
      location <select name="combo" id="combo" >
      <option>ooty
      <option>kodai
      <option>chennai
      </select>
      <input type="text" name="txtCombo" id="txtCombo">
      <input type="button" value="add" onclick="addition()">
      </form>
      </body>
      </html>
      Regards,
      Shravs
      Last edited by gits; Mar 21 '10, 03:51 PM. Reason: fix code tags

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        so first you would need a check that will perform a loop through your existing option-nodes and test whether an option with the same textnode exists already or not. if so you would just need to display an alert() ...

        Comment

        Working...