Hi,
I have a jQuery code inside an ascx that takes a cell content from a gridview and manipulate it, then write it to other cell.
It is activated by a click on the gridview row.
(Each row has a 1st cell with Word file name. The user clicks on a row - jQuey takes the file name in first cell and changes the extension to flv/mp3 - checks if there is a file with the new name - if there is a file it creates an image link to that file) I worked hard on this code but now the client want that the event (meaning that the image links that show if there is a file with the flv/mp3 ) will occur on page load.
I do not want to write all again and think there should be a way to just change the click event.
The problem is I am not very efficient with jQuery :) Can some jQuery hotshot help on this?
Here is the code (I am not proud with this code but it does the job):
<script type="text/javascript">
jQuery(function() {
jQuery(".SearchResultsGV > tbody > tr:not(:has(table, th))")
.css("cursor", "pointer")
.one("click", function(e) {
var jQuerycell = jQuery(e.target).closest("td");
var jQuerycurrentCellText = jQuerycell.text();
var jQueryleftCellText = jQuerycell.prev().text();
var jQueryrightCellText = jQuerycell.next().text();
var jQuerycolIndex = jQuerycell.parent().children().index(jQuerycell);
var jQuerycolName = jQuerycell.closest("table")
.find('th:eq(' + jQuerycolIndex + ')').text();
//Check media 1
jQuery.ajax({
url: 'http://dtora.org.il/Portals/0/Shiurim/' + jQuerycell.parent().children().first().text().replace('.doc', '.mp3'),
type: 'HEAD',
error:
function() {
//do something depressing
jQuery(jQuerycell.parent().children().last()).append("<img src=http://dtora.org.il/Portals/0/images/noFiles.png />");
},
success:
function() {
//do something cheerful :)
var jQueryMedia1Name = ('<a href=http://dtora.org.il/Portals/0/Shiurim/' + jQuerycell.parent().children().first().text().replace('.doc', '.mp3') + '><img class="soundFile" src=http://dtora.org.il/Portals/0/images/Music.png /></a>')
jQuery(jQuerycell.parent().children().last()).append(jQueryMedia1Name);
}
});
//Check media 2
jQuery.ajax({
url: 'http://dtora.org.il/Portals/0/Shiurim/' + jQuerycell.parent().children().first().text().replace('.doc', '.flv'),
type: 'HEAD',
error:
function() {
//do something depressing
jQuery(jQuerycell.parent().children().last()).append("<img src=http://dtora.org.il/Portals/0/images/noFiles.png />");
},
success:
function() {
//do something cheerful :)
var jQueryMedia2Name = ('<a href=http://dtora.org.il/Portals/0/Shiurim/' + jQuerycell.parent().children().first().text().replace('.doc', '.flv') + '><img class="videoFile" src=http://dtora.org.il/Portals/0/images/Video.png /></a>')
jQuery(jQuerycell.parent().children().last()).append(jQueryMedia2Name);
}
});
});
});
</script>