dropdownlist question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    #1

    dropdownlist question

    Hi, I have the following Javascript that fires from an onChange event
    for a dropdownlist. When the dropdownlist changes, it shows a dialog
    box with Yes and Cancel. If I press Cancel, I want the value currently
    in the dropdownlist to be reset back to what it was before. How do you
    do reset it back?

    Thank you a lot in advance
    David

    <script>
    function pleaseConfirm()
    {
    return confirm("confir m you want to do this");
    }
    </script>
  • lancewlarsen

    #2
    Re: dropdownlist question

    Ok -- found your question while I was looking to solve the same problem --
    didn't find a good answer anywhere -- so here's the resolution that I came
    up with -- and works quite well for my intended functionality, which is to
    make certain that before a user changes a drop down that they receive a
    "confirmati on" box and must answer "ok" prior to actually being able to
    change said drop down value.

    <select name="dropdownA rea"
    onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
    <option value="1">Optio n 1</option>
    <option value="2">Optio n 2</option>
    <option value="3">Optio n 3</option>
    </select>

    Now -- had to use the onFocus event as opposed to using the onChange event
    -- as using the latter would have entailed that I reset the form values
    (or something) to be able to get back the original drop down value if they
    did not click "ok". And by blurring the focus -- until they hit "ok" --
    they'll receive the confirmation box when they set focus on the dropdown.

    Additionally, I added a default state -- in this case "< Select Option >"
    -- I didn't want it to ask them of the dropdown was on this default state
    -- so modified as follows:

    <select name="dropdownA rea"
    onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
    this.blur(); };}">
    <option value="-1">&lt; Select Option &gt;</option>
    <option value="1">Optio n 1</option>
    <option value="2">Optio n 2</option>
    <option value="3">Optio n 3</option>
    </select>

    Hope that helps -- if you find alternate means of accomplishing this --
    I'd be interested in seeing it...

    ...Lance W. Larsen


    Comment

    • lancewlarsen

      #3
      Re: dropdownlist question

      Ok -- found your question while I was looking to solve the same problem --
      didn't find a good answer anywhere -- so here's the resolution that I came
      up with -- and works quite well for my intended functionality, which is to
      make certain that before a user changes a drop down that they receive a
      "confirmati on" box and must answer "ok" prior to actually being able to
      change said drop down value.

      <select name="dropdownA rea"
      onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
      <option value="1">Optio n 1</option>
      <option value="2">Optio n 2</option>
      <option value="3">Optio n 3</option>
      </select>

      Now -- had to use the onFocus event as opposed to using the onChange event
      -- as using the latter would have entailed that I reset the form values
      (or something) to be able to get back the original drop down value if they
      did not click "ok". And by blurring the focus -- until they hit "ok" --
      they'll receive the confirmation box when they set focus on the dropdown.

      Additionally, I added a default state -- in this case "< Select Option >"
      -- I didn't want it to ask them of the dropdown was on this default state
      -- so modified as follows:

      <select name="dropdownA rea"
      onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
      this.blur(); };}">
      <option value="-1">&lt; Select Option &gt;</option>
      <option value="1">Optio n 1</option>
      <option value="2">Optio n 2</option>
      <option value="3">Optio n 3</option>
      </select>

      Hope that helps -- if you find alternate means of accomplishing this --
      I'd be interested in seeing it...

      ...Lance W. Larsen


      Comment

      • lancewlarsen

        #4
        Re: dropdownlist question

        Ok -- found your question while I was looking to solve the same problem --
        didn't find a good answer anywhere -- so here's the resolution that I came
        up with -- and works quite well for my intended functionality, which is to
        make certain that before a user changes a drop down that they receive a
        "confirmati on" box and must answer "ok" prior to actually being able to
        change said drop down value.

        <select name="dropdownA rea"
        onfocus="if (!confirm('Are you sure?')) { this.blur(); }">
        <option value="1">Optio n 1</option>
        <option value="2">Optio n 2</option>
        <option value="3">Optio n 3</option>
        </select>

        Now -- had to use the onFocus event as opposed to using the onChange event
        -- as using the latter would have entailed that I reset the form values
        (or something) to be able to get back the original drop down value if they
        did not click "ok". And by blurring the focus -- until they hit "ok" --
        they'll receive the confirmation box when they set focus on the dropdown.

        Additionally, I added a default state -- in this case "< Select Option >"
        -- I didn't want it to ask them of the dropdown was on this default state
        -- so modified as follows:

        <select name="dropdownA rea"
        onfocus="if (this.value != '-1') {if (!confirm('Are you sure?')) {
        this.blur(); };}">
        <option value="-1">&lt; Select Option &gt;</option>
        <option value="1">Optio n 1</option>
        <option value="2">Optio n 2</option>
        <option value="3">Optio n 3</option>
        </select>

        Hope that helps -- if you find alternate means of accomplishing this --
        I'd be interested in seeing it...

        ...Lance W. Larsen


        Comment

        Working...