Link to home
Start Free TrialLog in
Avatar of Michael Carrillo
Michael CarrilloFlag 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!
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

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

Thanks
Rainer
Avatar of Michael Carrillo

ASKER

I am using SharePoint 2007 Enterprise.
Could you try:
jQuery("select[title='ISR Status']").children("option[value='Approval Review']").attr("selected","selected");
Still did not work.  
The value selected remains 'ISR Created'
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");
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
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
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was it!  It works!

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


Thanks!
I appreciate your patience!

Thanks!