COMBO BOX - Javascript reset combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neo3114
    New Member
    • Jan 2007
    • 6

    COMBO BOX - Javascript reset combo box

    Hi all,

    I have the following form on my page


    [HTML]<form>
    <select name= "combo1"onchang e="jscript:docu ment.location.h ash=this.value" >
    <option value="">Please Select Building</option>
    <option value="build1"> building 1</option>
    </select>
    <input type="reset">
    </form>[/HTML]

    What i want is to do away with the reset button, and have the box automatically reset after the jscript has jumped to the correct tag.

    How can i do this?

    Thanks in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I'm not sure what you mean by jumping to the correct tag, but you can call a function that will reset it for you, either by setting the combo value back to the original value, e.g. build1, or calling the form reset method:
    Code:
    document.getElementById(formid).reset();

    Comment

    • neo3114
      New Member
      • Jan 2007
      • 6

      #3
      how would i write that into the combo onchange, i dont know how to make the two commands run one after the other.
      thanks

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        There's two ways: either put it all in the onchange using a semi-colon (;) in between or call a function instead and put both statements in that function.

        Comment

        • neo3114
          New Member
          • Jan 2007
          • 6

          #5
          ok tried the following

          [HTML]<form>
          <form id="menu" name="menu">
          <select name= "combo1"onchang e="jscript:docu ment.location.h ash=this.value; document.getEle mentById('menu' ).reset()">
          <option value="">Please Select Building</option>
          <option value="build1"> building 1</option>
          </select>
          <input type="reset">
          </form>[/HTML]

          i am so new to this javascript thing, but i cant make head nor tail of this

          i appreciate your help

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            this is the best way to customize the reset button works ....not having the default behaviours of form.reset()... ..
            <input type = button value = Reset onclick = reset()>

            function reset()
            {
            //ur code is here...
            document.getEle mentByName(comb o_'name').selec tedIndex = 0;
            }

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Try
              [HTML]<select name="combo1" onchange="javas cript:document. location.hash=t his.value; document.getEle mentById('menu' ).reset()">[/HTML]
              Note, jscript is IE-specific, use javascript instead. In fact, you don't even need "javascript :".
              Also, get rid of that first form tag (the one that has no id).

              Comment

              • neo3114
                New Member
                • Jan 2007
                • 6

                #8
                Acoder thanks very much for your help and your patience.

                That seems to work a treat!

                Thanks again

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  No problem. Glad you got it solved.

                  Comment

                  Working...