?
Solved

JQuery/Datatables

Posted on 2013-06-11
10
Medium Priority
?
296 Views
Last Modified: 2013-06-19
How do you get all of the values from the drop down boxes in a datatable?
0
Comment
Question by:capturetheflag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39237539
what drop down boxes?
which datatable?
is that a general question?
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 39237632
Hello sedgwick,

I have a jQuery datatable with drop down boxes for route and sub-route for each record in the datatable.  The route values are approved or not approved.  If approved take sub-route one or two. If route value is not approved take sub-route three or four.
As an example record one could have a route of approved and a sub-route of two and,
record two could have a route of not-approved and sub-route of four.

How do I get(store/retrieve/display) all the values for these two records?

Thanks for your help.
0
 
LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 900 total points
ID: 39237703
You have not provided enough information - some code would help or even better a link to your site.

Also your request is ambiguous

How do you get all of the values from the drop down boxes in a datatable

could mean you want to retrieve all the options in the drop downs. I am assuming you want to get the SELECTED values in the dropdowns of each record

Your explanation about route and sub-route does not really help - you are explaining how your data relates to each other when what it seems you are asking is how to retrieve the values from the datatable.

It would help us to know what you want to do with this data

Are you going to use it in the document or
Are you going to submit it to the server
It would help if you gave us some information on what your datatable implementation looks like
0
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 
LVL 1

Author Comment

by:capturetheflag
ID: 39237834
Hello,

Thank you for your help.  Here is the code I am working with.

                <div class="contentBorder">
                  <div>
                    <table id="processEligibilityTable" class="dataDisplayTable">
                      <thead>
                        <tr class="sortable">
                          <th id="Category"     >Category</th>
                          <th id="Eligibility"  >Eligibility</th>
                          <th id="Amount"    >Amount</th>
                          <th id="Elig Date"    >Elig Date</th>
                                                                                                <th id="Route"        >Route</th>
                                                                                                <th id="SubQueue"     >Subqueue</th>
                          <th id="Asst Type"    >Asst Type</th>h
                          <th id="Award Level"  >Award Level</th>h
                          <th id="Schedule Date">Schedule Date</th>
                          <th id="Assistance Id">Astn Id</th>h
                          <th id="Program"      >Program</th>h
                          <th id="Approved"     >Approved</th>h
                          <th id="Workpacket Id">Workpacket Id</th>
                          <th id="Rejection Rsn Tx">Rejection Rsn Tx</th>
                        </tr>
                      </thead>
                      <tbody>
                            <tr>
                <td headers="Category"><a id="worksheetEditViewLinkId" href="">Dental</a></td>
                              <td headers="Eligibility">APVP - Appeal Partial Approval</td>
                              <td headers="Amount">0</td>
                              <td headers="Elig Date">05/29/2013</td>
                              <td header="Route">
                                <select id="routeSel">
                                  <option value="1">Approval</option>
                                  <option value="2">Ineligible</option>
                                </select>
                              </td>
                              <td header="Subqueue">
                                <select id="subqueueSel">
                                  <option value="1">Approval</option>
                                  <option value="2">Ineligible</option>
                                  <option value="3">Supervisor - Resolution</option>
                                </select>
                              </td>
                              <td headers="Asst Type">Initial</td>
                              <td headers="Award Level">First</td>
                              <td headers="Schedule Date">&nbsp;</td>
                              <td headers="Assistance Id">5</td>
                              <td headers="Program">      OTH</td>
                              <td headers="Approved">     &nbsp;</td>
                              <td headers="Workpacket Id">4</td>
                            </tr>
                            <tr>
                              <td headers="Category"><a id="worksheetEditViewLinkId" href="">Expedited Assistance Category C</a></td>
                              <td headers="Eligibility">EA- Expedited Assistance Category C</td>
                              <td headers="Amount">$2,631.00</td>
                              <td headers="Elig Date">07/06/2011</td>
                              <td header="Route">
                                <select id="routeSel">
                                  <option value="1">Approval</option>
                                  <option value="2">Ineligible</option>
                                </select>
                              </td>
                              <td header="Subqueue">
                                <select id="subqueueSel">
                                  <option value="1">Approval</option>
                                  <option value="2">Ineligible</option>
                                  <option value="3">Supervisor - Resolution</option>
                                </select>
                              </td>
                              <td headers="Asst Type">Initial</td>
                              <td headers="Award Level">First</td>
                              <td headers="Schedule Date">03/13/2013</td>
                              <td headers="Assistance Id">3</td>
                              <td headers="Program">      HA</td>
                              <td headers="Approved">     Y</td>
                            </tr>
                      </tbody>
                    </table>
                  </div>
                </div>

SCRIPT>>>
  var processEligibilityDataTable;

$(document).ready(function()
{
                processEligibilityDataTable = $('#processEligibilityTable').dataTable(
                                                {
                                                                "bAutoWidth"   : false,   // Disable automatic column width calculation
                                                                "bPaginate"                        : false,   // Disable pagination
                                                                "bLengthChange"            : false,   // Disable selecting length of table
                                                                "bInfo"                                 : false,   // Disable table information display
                                                                "bFilter"                               : false,   // Disable the filter search box
                                                                "oLanguage"                      :                                               // Default empty table message
                                                                                {"sEmptyTable": "&nbsp;"},
                                                                "aaSorting"                         : [[1,"desc"], [3,"desc"]], //Default sorting by Elig Start Date, then Check in Date
                                                                "asStripClasses":              ['','blueBG']        // Alternate row highlighting
                                                });
                                                processEligibilityDataTable.fnSetColumnVis( 6, false );
                                                processEligibilityDataTable.fnSetColumnVis( 7, false );
                                                processEligibilityDataTable.fnSetColumnVis( 8, false );
                                                processEligibilityDataTable.fnSetColumnVis( 9, false );
                                                processEligibilityDataTable.fnSetColumnVis(10, false );
                                                processEligibilityDataTable.fnSetColumnVis(11, false );
                                                processEligibilityDataTable.fnSetColumnVis(12, false );
                                                processEligibilityDataTable.fnSetColumnVis(13, false );
});

function checkProcessEligibility() {
                oTableLocal = processEligibilityDataTable;
                var rowsArray = oTableLocal.fnGetNodes();
                for (var i = 0; i < rowsArray.length; i++){
                                var route = oTableLocal.fnGetData(rowsArray[i],4 );
                                var routeSelect = $('select', rowsArray[i]);
                                var test = routeSelect[0].selectedIndex //gets the selected index
                                var name = "";
                                var value = "";
    if (test != 0) {  //has a selection
      // This is where I am lost.   I don't know the syntax for geting these attributes (thanks for your help))
                                  name = routeSelect[0][test].name; // don't know how to get the selectes name
                                  value = routeSelect[0][test].value; // don't know how to get the selectes v  alue
                                }
                                if (route == null || route == "") {
                                                processEligibilityRouteNotSet = true;
                                                return;
                                }
                                summaryElgy += oTableLocal.fnGetData(rowsArray[i],13 ) + (rowsArray.length > 1 ?" ," : "" );
                                elgyList += oTableLocal.fnGetData(rowsArray[i],10 ) + "=" + oTableLocal.fnGetData(rowsArray[i],13 ) + crlf;
                }
}

Open in new window

0
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 900 total points
ID: 39237982
Ok - there are major issues with your table.

Firstly you have duplicate ID's for your select boxes - ID's have to be unique in an html document.

To get the selected value of a select you use the .val() function

$('#selector').val()

In your case the ID won't work because you have declared duplicate ID's

What you need to do is link the ID to the index of the row so for instance

routeSel_1, routeSel_2 etc

Then you can get the value in a loop by

$('#routeSel_" + id).val();
0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 300 total points
ID: 39238144
You are looking for chained select see example in ref site:
http://www.jagadishwor.net/2011/05/5-php-ajax-mysql-javascript-chain-select/
0
 
LVL 1

Author Comment

by:capturetheflag
ID: 39238529
I don’t care about having unique ID on the select boxes in a table, the table is generated using JSP so for all purposes in this example you can remove the id

By selecting input elements in a datatable by ID runs the risk of getting an element from a different row, were a mistake made in the ID assignment, surely there is a more accurate way of getting row input elements.

Thanks for your help.
0
 
LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 900 total points
ID: 39238706
There is but it is difficult to say how to integrate this to what you have. Your loop is based on the return date from
var rowsArray = oTableLocal.fnGetNodes();

Open in new window

In a table row you can get the select by giving the different selects a class and then from the <tr> element doing

For instance
...
	$('tr').click(function(e) {
		e.preventDefault();
		alert($(this).find('select.routeSel').val());
	});
...

Open in new window

0
 
LVL 17

Assisted Solution

by:jrm213jrm213
jrm213jrm213 earned 300 total points
ID: 39241686
You should care about having unique id values because id is a required attribute for all HTML elements and it is also required to be unique. If the table is or isn't generated by JSP doesn't matter at all, whoever coded the jsp should fix the code to write valid HTML. Or one day you will wonder why your code doesn't work in X browser or mobile device and surprise, it's because the HTML is invalid.

How exactly does selecting by ID assignment run the risk of getting a value from a wrong row? Is your code that creates the table flawed? If there is a risk of the id being wrong how do you have any idea what row the drop down values correlate to?

That being said, if you just want to get the all the values of all the select boxes then you can iterate them with the each function
 $('select option').each(function(index)
            {
            	console.log(this.text + ": " + this.value);   //put them into a variable or another field or whatever you want to do with them here
            });

Open in new window

0
 
LVL 1

Author Closing Comment

by:capturetheflag
ID: 39259689
Thanks for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question