We help IT Professionals succeed at work.

JavaScript to set default value on SharePoint form field

Matt Pinkston
on
838 Views
Last Modified: 2017-03-09
I found the below script, placed it in but no change...  is there any obvious issue?

<script src=”https://code.jquery.com/jquery-1.11.0.min.js”</script>
<script type=”text/javascript”>

$(document).ready(function() {

$(“select[Title=’PursuitType’]”).val(‘CLIN 6AG’);

});

</script>
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Works for me - so either you don't have a select with that title or there is some error on your page.

1. Check your console for errors (F12)
2. Check that you have a select with Title PursuitType

This sample demonstrates the code works

Aside: why are you using a title as a selector? Surely the <select> has at least a name or an id - which would be more logical?
Matt PinkstonEnterprise Architect

Author

Commented:
Thanks for the reply

<SharePoint:FormField runat="server" id="ff2x{$Pos}" ControlMode="New" FieldName="PursuitType" __designer:bind="{ddwrt:DataBind('i',concat('ff2x',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@PursuitType')}" />

When I try to add title= it says that is not valid
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Ok but I ask again why are you trying to reference the select by title?

Why not ID or Class?
Matt PinkstonEnterprise Architect

Author

Commented:
the JavaScript I found asks for title????

$(“select[Title=’PursuitType’]”).val(‘CLIN 6AG’);
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Matt PinkstonEnterprise Architect

Author

Commented:
Thanks....
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome.