Michael Carrillo
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:
Page Rendered Code:
jquery assignment code:
$("tr.ISRStatus select").selected("Approva l Review");
I have also tried:
$("tr.ISRStatus select").val("Approval Review");
$("tr.ISRStatus select").selected.val("App roval Review");
Neither line of jquery appears to work. The value remains defaulted to "ISR Created".
Any help is appreciated!
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>
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>
jquery assignment code:
$("tr.ISRStatus select").selected("Approva
I have also tried:
$("tr.ISRStatus select").val("Approval Review");
$("tr.ISRStatus select").selected.val("App
Neither line of jquery appears to work. The value remains defaulted to "ISR Created".
Any help is appreciated!
ASKER
I am using SharePoint 2007 Enterprise.
Could you try:
jQuery("select[title='ISR Status']").children("optio n[value='A pproval Review']").attr("selected" ,"selected ");
jQuery("select[title='ISR Status']").children("optio
ASKER
Still did not work.
The value selected remains 'ISR Created'
The value selected remains 'ISR Created'
ASKER
I also tried the following with no success:
$("tr.ISRStatus select").children("option[ value='App roval Review']").attr("selected" ,"selected ");
$("select[title='ISR Status']").children("optio n[selected ='selected ']").val(" Approval Review");
$("select[title='ISR Status']").children("optio n[selected ='selected ']").attr( "value","A pproval Review");
$("tr.ISRStatus select").children("option[
$("select[title='ISR Status']").children("optio
$("select[title='ISR Status']").children("optio
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
I try to repro on a 2007 dev image.
How did you load / integrate jQuery and how do you call the function?
Thanks
Rainer
ASKER
Code is inserted where the arrows are (===>)
The code should execute when the save button is enabled.
<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>
The code should execute when the save button is enabled.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was it! It works!
$("select[title='ISR Status']").val('Approval Review');
Thanks!
$("select[title='ISR Status']").val('Approval Review');
Thanks!
ASKER
I appreciate your patience!
Thanks!
Thanks!
which version and edition of SharePoint do you use?
Thanks
Rainer