Avatar of Matt Pinkston
Matt Pinkston
 asked on

JavaScript to set default value on SharePoint form field

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>
JavaScript

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
Julian Hansen

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 Pinkston

ASKER
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
Julian Hansen

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

Why not ID or Class?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Matt Pinkston

ASKER
the JavaScript I found asks for title????

$(“select[Title=’PursuitType’]”).val(‘CLIN 6AG’);
ASKER CERTIFIED SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Matt Pinkston

ASKER
Thanks....
Julian Hansen

You are welcome.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.