Hmong Developers
To provide a long lasting and reliable place for developers to meet, share, learn new knowledge, network with business clients, and inspire new developers to continue learning and growing.
 
*
Welcome, Guest. Please login or register. September 05, 2010, 06:08:12 am


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: JS: get value in a datalist control  (Read 172 times)
0 Members and 1 Guest are viewing this topic.
passion
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 18


« on: July 01, 2010, 05:37:04 pm »

I'm an okay programmer on JavaScript and it has it's values when it comes down to client side events.

So, here's my situation ...
I have a server side data list control that binds from a stored procedure query.
I have check boxes in that data list for each row.
I have created a JS function to generate a number to be assigned to a row when a check box is checked.

The issue ...
I cannot retrieve the value of the client side generated number from each row.

If you need any clarifications, whatsoever, let me know.

Code:
function display(chkId, lblId, intIncrement)
        {
            var frm = document.forms[0];   
            //var hnd = document.forms[0].hdnMbr;
            //var arry = new Array();
            for(i=0;i<frm.elements.length;i++)
                {                       
                   if(frm.elements[i].id == chkId)
                        {                               
                            if(frm.elements[i].checked)
                            {
                                var intChecked = numChecked();
                                var intBarNum;
                                var span = document.getElementsByTagName("span");
                                for(ii=0;i<span.length;ii++)
                                {
                                    if (span[ii].id == lblId)
                                    {
                                        intBarNum = parseInt(intIncrement) + parseInt(intChecked);
                                        span[ii].innerHTML = intBarNum;
                                        span[ii].innerText = intBarNum;
                                        //hdn.value = intBarNum;
                                        //arry[ii] = intBarNum;
                                        return;
                                    }
                                }                 
                            }
                           
                            if(frm.elements[i].checked == false)
                            {
                                var span = document.getElementsByTagName("span");
                                for(ii=0;i<span.length;ii++)
                                {
                                    if (span[ii].id == lblId)
                                    {
                                        span[ii].innerHTML = ''
                                        span[ii].innerText = ''
                                        //hdn = intBarNum;
                                        //arry[ii] = intBarNum;                                       
                                        return;
                                    }
                                }
                            }
                        }
                }         
        }   
       
        //need to fix to not duplicate numbers
        function numChecked()
        {
            var cntChkbx=0;           
            var frm = document.forms[0]; 
            for(i=0;i<frm.elements.length;i++)
            {
                if(frm.elements[i].type == "checkbox")
                {
                    if(frm.elements[i].checked)
                    cntChkbx++;
                }           
            }           
            return cntChkbx;
        }
Logged

Language: VB.NET
jetter
Developer
Newbie
*****

Karma: +0/-0
Offline Offline

Posts: 46


« Reply #1 on: July 02, 2010, 02:46:21 pm »

Quote
I cannot retrieve the value of the client side generated number from each row.

Are you trying to retrieve the value via server side scripting (aka vb.net, c# etc) or js?  

Looking at the code, js should get the value once you set it in your span; either HTML or text should work fine but in this case just text should be enough to get the number in there and the ability to retrieve it via js and do something with it.

If you are trying to retrieve the value via server side scripting, you will never see it because the changes resided on the client and changes were made on the client, the server side script will never knew what happen; in this case if you want the server side script to see the changes, it has to be ajax.  

hope this helps; if not I might be missing some more info.
« Last Edit: July 02, 2010, 02:50:12 pm by jetter » Logged
passion
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 18


« Reply #2 on: July 02, 2010, 06:59:51 pm »

Quote
If you are trying to retrieve the value via server side scripting, you will never see it because the changes resided on the client and changes were made on the client, the server side script will never knew what happen; in this case if you want the server side script to see the changes, it has to be ajax. 

Yes! That's what I'm trying to do.

The JS values are displayed in the data list, therefore I was trying to retrieve those values using server side code. Logically, I knew I can't retrieve JS values but I just had to ask if anyone knew of way.

I'll give AJAX a try. Thanks Jetter!
Logged

Language: VB.NET
passion
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 18


« Reply #3 on: July 02, 2010, 09:18:52 pm »

OKAY! RESOLVED!  Cheesy

I decided to use a queue data structure to handle the generated numbers. One of the requirements was that they wanted to use all numbers provided and no skipping numbers or gaps.

EX.

Code:
queue.enqueue(123)
queue.enqueue(124)

[X] Amy #123 (queue.dequeue)
[X] Cha  #124  (queue.dequeue)

hmm ... i don't need Cha on the list

[ ] Cha   (queue.enqueue(124))

I should have thought of using stacks and queues earlier. Wasted a good 6 hours on creating a JavaScript function hoping to bypass autopostback, but then realized that i needed to post back anyways to get the client side values to register in the server side.

Logged

Language: VB.NET
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC

Advertise with HmongAd.com
Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM