none
Choice columns in SharePoint List

    Question

  • hi

    I have created a simple list with a "Choice" column, i have three entries in my dropdown

    First Entry

    Second Entry

    Third Entry.

    When user creates a new item, default value in the drop down  is blank, i want user must select a value, so i have selected "Required value" option for tihs column, no if user try to save with blank value in the dropdown, a requried field error is displayed.

    Is it possible if i add "Please select a value" in the drop down as first value.

    Wednesday, October 13, 2010 8:39 AM

Answers

  • Hi,

    Can you supply default value??

    Select "Default value" is "Choice".and pass any entry as default

    Let me know if it works


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Shafaqat Wednesday, October 13, 2010 9:50 AM
    Wednesday, October 13, 2010 9:17 AM
  • I think Hemendra's solution is best. But if you are desparate to add "Please select a value" as default option in dropdown list then add first option as "Please select a value" in choice column and set it as default. Then add custom javascript validation on new and edit forms from Sharepoint Designer so user will not select first option.

    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    • Marked as answer by Shafaqat Wednesday, October 13, 2010 9:50 AM
    Wednesday, October 13, 2010 9:34 AM

All replies

  • Hi,

    Can you supply default value??

    Select "Default value" is "Choice".and pass any entry as default

    Let me know if it works


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    • Marked as answer by Shafaqat Wednesday, October 13, 2010 9:50 AM
    Wednesday, October 13, 2010 9:17 AM
  • I think Hemendra's solution is best. But if you are desparate to add "Please select a value" as default option in dropdown list then add first option as "Please select a value" in choice column and set it as default. Then add custom javascript validation on new and edit forms from Sharepoint Designer so user will not select first option.

    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    • Marked as answer by Shafaqat Wednesday, October 13, 2010 9:50 AM
    Wednesday, October 13, 2010 9:34 AM
  • You both are right but i was wondering if there is a way to handle it without injecting any java script code.
    I cannot add "plese select...." as a value in my drop down.
    I would go for adding java script, please tell me how can i get my drop down at client side?
    Wednesday, October 13, 2010 9:50 AM
  • Please try below, add this at the end of the page (new/edit form).

    First i m creating dummy field in existing dropdown list and then adding validation

    <script type="text/javascript">
    
    	//Add default option
    	// Create an Option object    
    	var option = document.createElement("option");
    
    	// Add an Option object to dropdown list
    	document.getElementById("dropdownlistId").options.add(option);
    	
    	// Assign text and value to Option object
    	option.text = "Please select one";
    	option.value = "0";
    
    	//Set onchange event handler for validation
    	var itemValue = document.getElementById("dropdownlistId");
    	itemValue.onchange = function()
    	{
    		if (itemValue.value == "0") 
    		{
    			alert('Please select one');
    		}
    	};
    	
    </script>
    
    
    


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, October 13, 2010 10:47 AM
  • This will add default option on 0th index

    document.getElementById("dropdownlistId").options[0] = new Option("Please select one","0");
    


    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, October 13, 2010 10:55 AM
  • thanx

    how would i get "dropdownlistId", one way is to get it from the view source option, any other way?

    Wednesday, October 13, 2010 11:12 AM
  • I don't think there is any other way but lets check this article Refferencing SharePoint form fields with JavaScript
    Regards, Sandip Patil, .Net,Sharepoint Developer www.worldofsharepoint.com
    Wednesday, October 13, 2010 11:22 AM