onblur combo box alert

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prakashsurya
    New Member
    • Feb 2007
    • 29

    onblur combo box alert

    Helo i am going through the validations of date of birth in form
    which consists of three combo boxes dd/mm/yyyy. My aim is to use onblur function through which i hav to call a function. And the content of that function should display an alert message when ever the field is empty or when the starting index element i.e. select month or select date or select year is selected. So when we press the tab by selecting any of the three above i hav to get an alert box.
    Hope u will help me.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Changed title of thread.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by prakashsurya
      Helo i am going through the validations of date of birth in form
      which consists of three combo boxes dd/mm/yyyy. My aim is to use onblur function through which i hav to call a function. And the content of that function should display an alert message when ever the field is empty or when the starting index element i.e. select month or select date or select year is selected. So when we press the tab by selecting any of the three above i hav to get an alert box.
      Hope u will help me.
      Welcome to The Scripts.

      Post the code you have so far. So you want this behaviour whatever the value of the combo box? For that just pass the combo object to the function and use:
      Code:
      alert(this.value);
      In fact, you could even use:
      [HTML]<select ... onblur="alert(t his.value);">[/HTML] as long as you have set the value for each option.

      Comment

      • Logician
        New Member
        • Feb 2007
        • 210

        #4
        Originally posted by prakashsurya
        Helo i am going through the validations of date of birth in form
        which consists of three combo boxes dd/mm/yyyy. My aim is to use onblur function through which i hav to call a function. And the content of that function should display an alert message when ever the field is empty or when the starting index element i.e. select month or select date or select year is selected. So when we press the tab by selecting any of the three above i hav to get an alert box.
        Hope u will help me.
        If I understand correctly, I think this may do what you want: Link
        Rather less obtrusive than a conventional alert.

        Comment

        • prakashsurya
          New Member
          • Feb 2007
          • 29

          #5
          Please help me

          Hello gud evng
          I am having a small problem
          I am using three combo boxes for date of birth
          I wanna know how to use the onchange function in this combo boxes
          my aim is i hav to display some alert boxes when the user doesnt select anything or he has selected the first option i.e. Enter Date or Enter Month or Enter Year respectively.
          Hope u vl help me
          waiting for ur reply

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Threads merged. You are posting on the same topic, so I have merged the threads.

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You have two options that I would suggest to validate this.

              One is to call onblur, but not an alert box, but just an error message next to the boxes.

              The second option is to call the validation function on focus of the next element (as long as they have been on the date select boxes first). You can do this by setting a variable onfocus of the day select dropdown. Then onfocus of the element after the date dropdown, call the validation function (if the variable is set).

              Those are just two options to make it less obtrusive and more convenient for the user.

              With regards to the checking, just check if selectedIndex is 0.

              Comment

              • gauravgmbhr
                New Member
                • Feb 2007
                • 107

                #8
                well there are number of ways to have such a alert message
                u can use the onChange event instead of OnBlur.



                set the "select day", "select month"..... value Equal to 0

                Onchange=someFu nction(this)


                Code:
                function someFunction(obj) 
                {
                    if(obj.options[obj.selectedIndex].value==0 || obj.options[obj.selectedIndex].text=="")    {
                alert('field cannot be blank');
                
                }//end if
                }//end function

                Comment

                • prakashsurya
                  New Member
                  • Feb 2007
                  • 29

                  #9
                  thank u for ur valuable suggestion

                  Comment

                  • prakashsurya
                    New Member
                    • Feb 2007
                    • 29

                    #10
                    thank u
                    but here i am asking about onchange
                    can u please tell me how to use that one
                    and the properties of that function
                    waiting for ur reply

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      onchange is just the same. Just call a function which checks for the value of the date dropdown field. If the selectedIndex is 0, then show an error message:
                      [HTML]<select id="..." name="..." onchange="check Date(this)">[/HTML]
                      then in checkDate:
                      Code:
                      function checkDate(obj) {
                      if (obj.selectedIndex == 0) // display error message...
                      ...
                      }
                      Just one problem with onchange is that the user might accidentally select the first item - that is why you don't want to display an alert (might be annoying).

                      Comment

                      • gauravgmbhr
                        New Member
                        • Feb 2007
                        • 107

                        #12
                        Originally posted by prakashsurya
                        thank u
                        but here i am asking about onchange
                        can u please tell me how to use that one
                        and the properties of that function
                        waiting for ur reply

                        THERE IS A THING CALLED DOM(Document Object Model)
                        DOM tell u how to refer to each elemnt on the html page using java script
                        If u wanna read bout DOM try HTML DOM


                        THIS WILL LET U KNOW WHAT I DID IN THE FUNCTION
                        AND onchange works the same way as the Onblur

                        if u r using a div or select just use <select name="something " id="something" onchange="some_ javascript_func tion()"></select>

                        Comment

                        Working...