Getting Value from GridView Input Control using JavaScript - javascript

i am using Asp.Net Grid View Control having Template Field Columns. Which have Asp.Net Literal,TextBox and CheckBox Controls. I want to add each row Received Amount value when checkbox is Checked in each row. Below is my GridView.
I have accessed the Received Amount columns by JavaScript, but it gives me the whole Textbox in Alert
I want to get Value of that Textbox having Id=txtFeeRecAmount, not whole Control..
Below is my Script..
<script type="text/javascript">
function AddAmount(lnk) {
var row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex;
alert(rowIndex);
var amount = row.cells[2].innerHTML;
alert(amount);
}
</script>
Any Help, I want to get Value of Received Amount Column, when the CheckBox is checked.

As, there can be multiple textboxes. there you need to get the current value by
using jquery, this should work;
var amount = $(row.cells[2]).find('input').val();

As you tagged this question with jQuery I assume you are using it:
I want to get Value of that Textbox having Id=txtFeeRecAmount
$("#txtFreeRecAmount").val();

Related

Get selected check boxes values from table using Java script

I was using select Person_name = $('#selectedPerson').val()
person_name.length is showing 2 if selected 2 values.
Now i have changed to check boxes which is in table. If i am using person_name= document.getElementById("selectedPerson").innerText, person_name.length is not working. It is taking length of the content. I want to count of the person and it is value which i am selecting in check-boxes.
Thanks,
Raja.
Side note: an ID should only ever be applied to one element, so you want .selectedPerson not #selectedPerson if it's going to select two things.
var people = $('.selectedPerson');
var count = people.count;
var name = people.text();

How to update a row where checbox is checkbox is ticked - jquery

I want to update certain rows where checkboxes are ticked. I am able to get the rows every cells content but not able to update them.
I'm trying to update 7th cell's content like this:
$.each($("input[name='eachSelector']:checked").parents("tr"), function () {
$(this).find('td:eq(7)').innerText = "this is modified";
});
I am able to get all the cells values of the checked rows like this below values is an array.
$.each($("input[name='eachSelector']:checked").parents("td").siblings("td"), function () {
values.push($(this).text());
});
how to update the cells values and add some css to it
You have an error in your code. You are trying to use a DOM method on a jquery object. You should change this line
$(this).find('td:eq(7)').innerText = "this is modified";
to
$(this).find('td:eq(7)').text("this is modified");

how to update gridview textbox value in asp.net

i have a gridview with 6 columns in 5th column i have placed a text box, all the data are populating in the grid by executing stored procedure from database .
i have another textbox and ok button outside the gridview also.
Now i need to update the text box value in the gridview with the same text which is added to the outside the text box inside ok button click event ..
how can i do this without saving data to database?through javascript or jquery?
First thing if you are using ASP.NET 4 or above then you can set the ClientIDMode of your controls to Static so that it will be easier to work with the controls in jQuery. Alternatively you can also add custom attributes or class to your controls. Now since a gridview is rendered as html table in browser you can find the second row in the table (since first row is header row) and update the value like this:-
$(document).ready(function () {
$("#btnSubmit").click(function (e) {
e.preventDefault();
var firstRow = $('tr:nth-child(2)', $('#GridView1'));
var outsideText = $('#txtOutside').val();
$('#txtfoo', firstRow).val(outsideText);
});
}
Here I have considered that the ID of your gridview control is GridView1, the textbox which is outside is txtOutside, button is btnSubmit and the textbox which is outside is txtOutside.

how to add value to a particular column and row in a gridView in javascript?

I am trying to add a value to a gridView column on a specific row via Javascript. Previously I have done this via .NET.
But now I want to try this alternative:-
document.getElementById('<%=GridView1.ClientID%%>').rows[1].cells[1].value = IDentification#;
This is obviously not the correct syntax. Any ideas?
It should be innerHTML not value
document.getElementById('<%=GridView1.ClientID%>')
.rows[1]
.cells[1]
.innerHTML= yourvariable; //or "astring"
This will insert the text in your variable to 2nd row's 2nd column of the table rendered by the gridview.

How to create an OnChange "totaling" function from an unknown number of text fields

I'm having trouble figuring out how to do a simple Javascript task on fields in a table created with Rails 3.
My table has characteristic rows that the user adds using a form below (which updates the database and reloads the table partial).
The number of columns in the table is based on the number of attributes submitted in a different form. No matter how many columns are in a row, there is also a Total column after them. Each cell in the table has a text_field input, with an ID that is based on the row object id and the column object id.
What I'm trying to do is create an OnChange event for each of those cells, so that when a field value changes, the Total column gets updated with the total value in the text_field inputs of all cells in that row.
I don't know how to pass the Rails objects to Javascript (so I can cycle through the IDs), I can't figure out how to get the DOM element names and values if I use an action in the controller, and I don't know how to use RJS to do this either. Can anyone offer any help on how to do this? Thank you!
Sarah
If you use jQuery, you can set a class on the textboxes and listen to the change event on it.
example:
<input type="text" id="WhateverXXX" class="MyValue" />
<script type="text/javascript">
$(function(e) {
$('.MyValue').change(function(e) {
// update the total
});
});
</script>
In jQuery it'd be easy to iterate over all elements with the same class, so proper design of your document will help here.
Maybe something like this:
$('.thing_to_change').live('change', function() { retotal(); });
Your retotal function can be similar:
var total = 0;
$('.thing_to_change').each(function() { total = total + $(this).val() });

Categories

Resources