How to set a dropdown control to select item with index of 1?

lapucca
lapucca used Ask the Experts™
on
At my page at http://www.xraymind.org/CTSA/Section3.aspx, I would like to set all the dropdown for table B to select item with index 1.  Can and how would I do that?  Thanks.

        $(function() {
            $("select", "#tblB>tbody").val(0);
        });
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
example (index 3)

<select id="selectBox">
<option value="0">Number 0</option>
<option value="1">Number 1</option>
<option value="2">Number 2</option>
<option value="3">Number 3</option>
<option value="4">Number 4</option>
<option value="5">Number 5</option>
<option value="6">Number 6</option>
<option value="7">Number 7</option>
</select>

$('#selectBox option')[3].attr('selected', 'selected')

or

$('#selectBox option[value=3]')_.attr('selected', 'selected');

or

$('#selectBox option:nth-child(3)').attr('selected', 'selected')
$('#selectBox option:eq(3)').attr('selected', 'selected')
$('#selectBox option').get(3).attr('selected', 'selected')
Multitechnician
Top Expert 2014
Commented:
Don't forget to set the ID to table B (< table id="tblB") and use :

            $(function() {
                  $("select", "#tblB>tbody").attr("selectedIndex", 1);
            });

Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$(function() {
			$("select", "#tblB>tbody").attr("selectedIndex", 1);
		});
	});
</script>
</head>
<body>
<table id="tblB" width="960" border="0" align="center" cellpadding="5" cellspacing="1"> 
  <tr> 
    <td rowspan="2" class="fieldname1" scope="row">    
      
    B. Physiologic Monitoring </td> 
    <td colspan="5" class="submitfield"><strong>Time assessment period from time of ICU admission  following index procedure</strong></td> 
  </tr> 
  <tr> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
    <td class="fieldname">24 hours</td> 
 
    <td class="fieldname">48 hours</td> 
  </tr> 
  <tr> 
    <td class="fieldname" scope="row"> 
    <p>CVP monitored?</p></td> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
    <td class="datafield"> 
    <select name="selCVP24" id="selCVP24"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
    </select></td> 
    <td class="datafield"> 
    <select name="selCVP48" id="selCVP48"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
    </select></td> 
  </tr> 
  <tr> 
    <td height="31" class="fieldname" scope="row">LA </td> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
 
    <td class="datafield"> 
    <select name="selLA24" id="selLA24"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
    </select></td> 
    <td class="datafield"> 
    <select name="selLA48" id="selLA48"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
    </select></td> 
  </tr> 
  <tr> 
 
    <td height="23" class="fieldname" scope="row">EtCO2</td> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
    <td class="datafield"> 
    <select name="selEtCO2_24" id="selEtCO2_24"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
 
    </select></td> 
    <td class="datafield"> 
    <select name="selEtCO2_48" id="selEtCO2_48"> 
      <option></option> 
      <option value="Continuous">Yes Continuous</option> 
      <option value="Intermittently">Yes Intermittently</option> 
      <option value="No">No</option> 
    </select></td> 
  </tr> 
  
  <tr> 
    <td class="fieldname" scope="row"><p>SvO2 (%) </p></td> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtSvO2_24" id="txtSvO2_24" /> 
        <input type="checkbox" name="ckSvO2_24" id="ckSvO2_24" /> 
        Unknown
    </td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtSvO2_48" id="txtSvO2_48" /> 
        <input type="checkbox" name="ckSvO2" id="ckSvO2" /> 
        Unknown
    </td> 
  </tr> 
  
  <tr> 
    <td class="fieldname" scope="row">NIRS Monitoring </td> 
    <td colspan="3" class="submitfield">&nbsp;</td> 
    <td class="datafield"> 
        <select name="selNIRS24" id="selNIRS24"> 
        <option></option> 
          <option value="cerebral"> Cerebral</option> 
          <option value="somatic">Somatic</option> 
          <option value="not done">Not Done</option> 
        </select> 
    </td> 
    <td class="datafield"> 
        <select name="selNIRS48" id="selNIRS48"> 
        <option></option> 
          <option value="cerebral"> Cerebral</option> 
          <option value="somatic">Somatic</option> 
          <option value="not done">Not Done</option> 
        </select> 
    </td> 
  </tr> 
  <tr> 
    <td colspan="6" scope="row">&nbsp;</td> 
  </tr> 
  <tr> 
 
    <td class="fieldname" scope="row">C. Labs</td> 
    <td class="fieldname">0-6 inclusive hours</td> 
    <td class="fieldname">7-12inclusive hours</td> 
    <td class="fieldname">13-18 inclusive hours</td> 
    <td class="fieldname">18-24 hours</td> 
    <td class="fieldname">Closest to 48 hours</td> 
 
  </tr> 
  
  
  <tr> 
    <td class="fieldname" scope="row"><strong>Glucose-Highest value (mg/dL)</strong></td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtGlucose6" id="txtGlucose6" />      
        <input type="checkbox" name="ckGlucose6" id="ckGlucose6" /> 
        Unknown
    </td> 
    <td class="datafield"><input type="text" size="3" name="txtGlucose12" id="txtGlucose12" /> 
      <input type="checkbox" name="ckGlucose12" id="ckGlucose12" /> 
 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtGlucose18" id="txtGlucose18" /> 
      <input type="checkbox" name="ckGlucose18" id="ckGlucose18" /> 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtGlucose24" id="txtGlucose24" /> 
      <input type="checkbox" name="ckGlucose24" id="ckGlucose24" /> 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtGlucose48" id="txtGlucose48" /> 
      <input type="checkbox" name="ckGlucose48" id="ckGlucose48" /> 
 
Unknown</td> 
  </tr> 
  
  <tr> 
    <td class="fieldname" scope="row"><strong>Glucose-Lowest value  (mg/dL)</strong></td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtLowGlucose6" id="txtLowGlucose6" /> 
        <input type="checkbox" name="ckLowGlucose6" id="ckLowGlucose6" /> 
        Unknown
   </td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtLowGlucose12" id="txtLowGlucose12" /> 
        <input type="checkbox" name="ckLowGlucose12" id="ckLowGlucose12" /> 
        Unknown
    </td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtLowGlucose18" id="txtLowGlucose18" /> 
        <input type="checkbox" name="ckLowGlucose18" id="ckLowGlucose18" /> 
        Unknown
    </td> 
    <td class="datafield"> 
        <input type="text" size="3" name="txtLowGlucose24" id="LowGlucose24" /> 
        <input type="checkbox" name="ckLowGlucose24" id="ckLowGlucose24" /> 
        Unknown
        </td> 
 
    <td class="datafield"> 
        <input type="text" size="3" name="txtLowGlucose48" id="txtLowGlucose48" /> 
        <input type="checkbox" name="ckLowGlucose48" id="ckLowGlucose48" /> 
        Unknown
    </td> 
  </tr> 
  
  <tr> 
    <td height="32" class="fieldname" scope="row"><strong>Glucose control  (insulin)?  (Y/N at any time during period)</strong></td> 
    <td class="datafield"> 
        <select name="selGlucoseControl6" id="selGlucoseControl6"> 
          <option></option> 
          <option value="yes">Yes</option> 
          <option value="no">No</option> 
          <option value="unkown">Unkown</option> 
        </select> 
    </td> 
    <td class="datafield"> 
        <select name="selGlucoseControl12" id="selGlucoseControl12"> 
          <option></option> 
          <option value="yes">Yes</option> 
          <option value="no">No</option> 
          <option value="unkown">Unkown</option> 
        </select> 
    </td> 
    <td class="datafield"> 
        <select name="selGlucoseControl18" id="selGlucoseControl18"> 
          <option></option> 
          <option value="yes">Yes</option> 
          <option value="no">No</option> 
          <option value="unkown">Unkown</option> 
        </select> 
    </td> 
    <td class="datafield"> 
        <select name="selGlucoseControl24" id="selGlucoseControl24"> 
          <option></option> 
          <option value="yes">Yes</option> 
          <option value="no">No</option> 
          <option value="unkown">Unkown</option> 
        </select></td> 
    <td class="datafield"><select name="selGlucoseControl48" id="selGlucoseControl48"> 
      <option></option> 
      <option value="yes">Yes</option> 
      <option value="no">No</option> 
      <option value="unkown">Unkown</option> 
    </select></td> 
  </tr> 
  
  <tr> 
    <td height="32" class="fieldname" scope="row"><strong>Lactate (mmol/L)(record peak  value during specified time periods)</strong></td> 
    <td class="datafield"><input type="text" size="3" name="txtLactate6" id="txtLactate6" /> 
      <input type="checkbox" name="ckLactate6" id="ckLactate6" /> 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtLactate12" id="txtLactate12" /> 
      <input type="checkbox" name="ckLactate12" id="ckLactate12" /> 
 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtLactate18" id="txtLactate18" /> 
      <input type="checkbox" name="ckLactate18" id="ckLactate18" /> 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtLactate24" id="txtLactate24" /> 
      <input type="checkbox" name="ckLactate24" id="ckLactate24" /> 
Unknown</td> 
    <td class="datafield"><input type="text" size="3" name="txtLactate48" id="txtLactate48" /> 
      <input type="checkbox" name="ckLactate48" id="ckLactate48" /> 
 
Unknown</td> 
  </tr> 
  <tr> 
    <th scope="row">&nbsp;</th> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
    <td>&nbsp;</td> 
 
  </tr> 
  </table> 
</body>
</html>

Open in new window

Author

Commented:
Hi Leakim,
That works great!  I installed the intellisen file for jQuery in VS 2008 but that doesn't seem to be working.  Where can I find list of attribute for the control/  Would they be the same (and spelling) as the properties for the asp.net controls?  Thanks.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

leakim971Multitechnician
Top Expert 2014

Commented:
>Where can I find list of attribute for the control/  Would they be the same (and spelling) as the properties for the asp.net controls?

All attributes are available for asp.net control and the HTML element if this is simple control like TextBox, Button, Dropdown (select) and so on.

could you post your generated page ? (Right click on the page in your web browser and choose view source)

Author

Commented:
I thought if I give web address would be easier than posting bunch of code here.  Thanks .
Oops, right I haven't updated my newest code to that page yet.  
leakim971Multitechnician
Top Expert 2014

Commented:
>Oops, right I haven't updated my newest code to that page yet.  
eh eh right!

Thanks for the points! Have a nice week!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial