Click here to Skip to main content
15,746,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have tried so many different things but nothing seems to be working.
I have a screen with multiple input fields that I want to clear the values of after the user clicks OK on an alert box. This is working with the exception of 1 of my fields - a dropdown. It is actually clearing the values because when writing to the DB the values are cleared but it is still showing on the page.

When a particular field is cleared manually by the user, they are promoted to confirm if they intend to clear ALL inputs. If they answer Yes, I call an Ajax function from my javascript. This Ajax function calls a stored procedure. If this all returns as successful then I want to clear all the screen values - as I said this works for all except 1.
Below that I am trying to clear the dropdown by setting the selectedIndex to -1.
But on the screen, it is still showing the previously selected option.

Any other suggestions ? I have tried quite a few things..... setting it to selectedIndex = "0" etc just to see if I can actually change the selection but nothing works for me.

if (res == successMessage) {
               document.forms[0].reset();       /// THIS CLEARS ALL OTHER INPUTS
               document.getElementById("cmbList").selectedIndex = "-1";

What I have tried:

document.getElementById("cmbList").selectedIndex = "-1";

document.getElementById("cmbList").selectedIndex = "0";

document.getElementById("cmbList").value= "";

document.getElementById("cmbList").val()= "";
Updated 21-Jan-20 22:28pm

Share this answer

Can you try it without double quote.

document.getElementById("cmbList").selectedIndex = 0;

Mark answer if it works.!!
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