Avatar of Michael Carrillo
Michael Carrillo
Flag for United States of America asked on

jQuery assign dropdown field a value

What is the correct jquery syntax to assign (or select a value) a value to a dropdown field?
I am using SharePoint Designer 2007.

SharePoint Form Dropdown field code:

<tr class="ISRStatus">
	<td width="25%" class="ms-vb">
		<b>ISR Status:</b>
	</td>
	<td width="75%" class="ms-vb">
		<SharePoint:FormField runat="server" id="fXX{$Pos}" ControlMode="New" FieldName="ISR_x0020_Status" __designer:bind="{ddwrt:DataBind('i',concat('fXX',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@ISR_x0020_Status')}" />
	</td>
</tr>

Open in new window


Page Rendered Code:

<tr>
	<td width="25%" class="ms-vb">
		<b>ISR Status:</b>
	</td>
	<td width="75%" class="ms-vb">
	<span dir="none">
		<select name="XXX...DropDownChoice" id="XXX...._DropDownChoice"
title="ISR Status" class="ms-RadioText">

			<option selected="selected" value="ISR Created">ISR Created</option>
			<option value="Approval Review">Approval Review</option>
			....
			<option value="LOE Analysis">LOE Analysis</option>

		</select>
		<br>
	</span>Status of ISR
	</td>
</tr>

Open in new window


jquery assignment code:

$("tr.ISRStatus select").selected("Approval Review");
I have also tried:
$("tr.ISRStatus select").val("Approval Review");
$("tr.ISRStatus select").selected.val("Approval Review");

Neither line of jquery appears to work. The value remains defaulted to "ISR Created".

Any help is appreciated!
jQueryMicrosoft SharePointASP.NET

Avatar of undefined
Last Comment
Michael Carrillo

8/22/2022 - Mon
Rainer Jeschor

Hi,
which version and edition of SharePoint do you use?

Thanks
Rainer
Michael Carrillo

ASKER
I am using SharePoint 2007 Enterprise.
Rainer Jeschor

Could you try:
jQuery("select[title='ISR Status']").children("option[value='Approval Review']").attr("selected","selected");
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
Michael Carrillo

ASKER
Still did not work.  
The value selected remains 'ISR Created'
Michael Carrillo

ASKER
I also tried the following with no success:

$("tr.ISRStatus select").children("option[value='Approval Review']").attr("selected","selected");

$("select[title='ISR Status']").children("option[selected='selected']").val("Approval Review");

$("select[title='ISR Status']").children("option[selected='selected']").attr("value","Approval Review");
Rainer Jeschor

Hi,
I try to repro on a 2007 dev image.
How did you load / integrate jQuery and how do you call the function?
Thanks
Rainer
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Michael Carrillo

ASKER
Code is inserted where the arrows are (===>)

<script src="Jquery/jquery-1.7.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
$(document).ready(function()	{
....
// Validates Text Area Required Fields
    	$("tr.Required textarea").change(function() 	{
		var tarea=$.trim($(this).val()).length;
    		var tr_id=$(this).parent().parent().attr('id');
    		var fmType=$("tr.FormType input").val();

    		if(tarea==0){
    			$("tr#" + tr_id + ".Required div").show();
    			ValidInfo=ValidInfo - 1;
    			}
    		else {
    			$("tr#" + tr_id + ".Required div").hide();
    			ValidInfo=ValidInfo + 1;
    			}
 
			switch(fmType)	{
				case "A":
    				if (ValidInfo<3)	{
    					$("input[name=btnSave]").attr("disabled","disabled");
    					}
    				else	{
    					$("input[name=btnSave]").removeAttr("disabled");
===>
    					}
    				break;
    			case "B":
	    			if (ValidInfo<2)	{
	    				$("input[name=btnSave]").attr("disabled","disabled");
	    				}
	    			else	{
	    				$("input[name=btnSave]").removeAttr("disabled");
===>
	    				}
	    			break;
    			default:
    				alert("Error: Form Type is Missing");
    			}
    	});
....
});  // Closing Main Document Ready function	

</script>

Open in new window


The code should execute when the save button is enabled.
ASKER CERTIFIED SOLUTION
Rainer Jeschor

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
Michael Carrillo

ASKER
That was it!  It works!

$("select[title='ISR Status']").val('Approval Review');


Thanks!
Michael Carrillo

ASKER
I appreciate your patience!

Thanks!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes