Saturday, November 17, 2012

javascript – How to get textbox text from gridviews current row on click of linkbutton in that row

Here is my gridview



<asp:GridView ID=\"gvEmployee\" runat=\"server\" AutoGenerateColumns=\"false\" GridLines=\"Both\">
<Columns>
<asp:TemplateField HeaderText=\"Name\">
<ItemTemplate>
<asp:TextBox ID=\"txtName\" runat=\"server\" Text=\'<%#Eval(\"Name\") %>\'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField=\"Emailid\" HeaderText=\"EmailId\" />
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID=\"lnkgettext\" runat=\"server\" OnClientClick=\"return callme(<%= txtName.ClientID %>);\" Text=\"Gettextboxvalue\" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type=\"text/javascript\">
function callme(txt) {
alert(txt);
}
</script>


Onclick of LinkButton i want to get the value of a textbox from the current row of gridview


Please help me with javascript






Rating: 5 out of 5 based on 3 ratings



The post javascript – How to get textbox text from gridviews current row on click of linkbutton in that row appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-how-to-get-textbox-text-from-gridviews-current-row-on-click-of-linkbutton-in-that-row.html

c# – JQuery Autocomplete won't load remote values

Okay, so JQuery\’s autocomplete widget is driving me nutz!

I have tried numerous ways of loading the widget. I am currently getting the following:



Error: jQuery15105511000803127266_1353087819681 was not called -

parsererror



and the Response value (from firebug) appears to be System.string[] though I\’m not sure if it\’s an a string who\’s value is System.string[] or an actual system.string[] object.


Am I just being stupid, or am I missing something (please be kind in your answer to that last question…)?


My javascript is:



$(\"#clientName\").autocomplete({
source: function (request, response) {
$.ajax({
url: \"/supplier/apSupplierSearch/\",
data: { searchAPName: clientName.value },
dataType: \"json\",
type: \"POST\",
success: function (data) {
//response(data);
response($.map(data, function (item) {
return {
label: item.Name,
value: item.Name
}
}))
}
}); // ajax
}, // function [{
scroll: true,
scrollHeight: 600,
minLength: 4
});


My WebMethod is:



[WebMethod]
public string[] apSupplierSearch(string searchAPName)
{
IList<int> selectedPropertyIDs = new List<int>();
string currentRole = UserServices.GetCurrentRole();
Property currentProperty = UserServices.GetCurrentPropety();
List<ApSupplier> suppliers = ApSupplierQueries.GetApSuppliers(searchAPName, selectedPropertyIDs, currentRole, currentProperty);
List<string> supplierList = new List<string>();
foreach (ApSupplier supplier in suppliers)
{
supplierList.Add(supplier.Name);
}
return supplierList.ToArray();
}






Rating: 2 out of 5 based on 3 ratings



The post c# – JQuery Autocomplete won't load remote values appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/c-jquery-autocomplete-wont-load-remote-values.html

javascript – Jquery/JS scoping

This may be pretty simple but it\’s stumping me. I\’m trying to return a variable in javascript to another variable outside of the function\’s scope. For some reason, the assignment isn\’t occurring. Here\’s my code:



var time = Math.round(((new Date()).getTime())/1000);

// first call to get data
var power_now = get_data(<%= @user.id %>, time);

function get_data(user_id, timestamp){
var targetURL = \"get/user_data?time_now=\"+timestamp+\"&user_id=\"+user_id;
var power = 0;

$.get(targetURL, function(data){
power = data[0][\'power\'];
alert(power);
})

return power;
}

$(\'body\').html(\'<h1>\'+power_now+\',\'+power_then+\'</h1>\')


If I place alert(power) within the .get function, the value is correct; however if I place it outside of the .get function, the value is 0.


Maybe I\’m missing something about scoping in javascript?


Thanks!






Rating: 2 out of 5 based on 3 ratings



The post javascript – Jquery/JS scoping appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-jqueryjs-scoping.html

scope – Javascript: Do I need to put this.var for every variable in an object?

In C++, the language I\’m most comfortable with, usually one declares an object like this:



class foo
{
public:
int bar;
int getBar() { return bar; }
}


Calling getBar() works fine (ignoring the fact that bar might be uninitialized). The variable bar within getBar() is in the scope of class foo, so I don\’t need to say this->bar unless I really need to make it clear that I\’m referring to the class\’ bar instead of, say, a parameter.


Now, I\’m trying to get started with OOP in Javascript. So, I look up how to define classes and try the same sort of thing:



function foo()
{
this.bar = 0;
this.getBar = function() { return bar; }
}


And it gives me bar is undefined. Changing the bar to this.bar fixes the issue, but doing that for every variable clutters up my code quite a bit. Is this necessary for every variable? Since I can\’t find any questions relating to this, it makes me feel like I\’m doing something fundamentally wrong.




EDIT: Right, so, from the comments what I\’m getting is that this.bar, a property of an object, references something different than bar, a local variable. Can someone say why exactly this is, in terms of scoping and objects, and if there\’s another way to define an object where this isn\’t necessary?






Rating: 3 out of 5 based on 5 ratings



The post scope – Javascript: Do I need to put this.var for every variable in an object? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/scope-javascript-do-i-need-to-put-this-var-for-every-variable-in-an-object.html

javascript – How to know when asp.net ajax request has completed?

I have an asp.net web form with a button, label, scriptmanager and updatepanel controls. When I click the button, the label changes using ajax. How can I detect the change in the label using javascript?






Rating: 5 out of 5 based on 3 ratings



The post javascript – How to know when asp.net ajax request has completed? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-how-to-know-when-asp-net-ajax-request-has-completed.html

php – jQuery / Javascript – Dynamically insert text into URL

I have written some PHP that detects whether a user is visiting my blog posts using a mobile device or a computer.


Basically, I need a script that edits the URL dynamically if a user is visiting my blog post with a mobile.


For example, my blog post URLs are like this:



http://www.example.com/blog/blog-post-1/

http://www.example.com/blog/welcome-to-my-blog/

http://www.example.com/blog/another-blog-post/



Users should be dynamically redirected to:



http://www.example.com/m/blog/blog-post-1/

http://www.example.com/m/blog/welcome-to-my-blog/

http://www.example.com/m/blog/another-blog-post/



I also have the device detection working in PHP, so I just need the script to insert inside the PHP condition.


Any ideas?






Rating: 2 out of 5 based on 4 ratings



The post php – jQuery / Javascript – Dynamically insert text into URL appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-jquery-javascript-dynamically-insert-text-into-url.html

jquery – javascript while in array like php

hello i have some question how to do this with jquery or javacript ?


here is php code but i need jquery or javacript.



$price = \'270\';

$allowed_sms_prices = array(
5,7,10,15,20,25,30,35,39,40,
45,49,50,55,59,60,69,75,79,85,
89,95,100,125,150,175,200,225,250,275,
300,310,315,320,325,330,335,340,345,350,
355,360,365,370,375,380,385,390,395,400,
405,410,415,420,425,430,435,440,445,450,
455,460,465,470,475,480,485,490,495,500
);

while( ! in_array( $price, $allowed_sms_prices ) )
{
$price = $price + 1;
}
echo $price;






Rating: 1 out of 5 based on 3 ratings



The post jquery – javascript while in array like php appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-javascript-while-in-array-like-php.html

canvas – How to generate an Image from imageData in javascript?

I would like to know if there is any way to create a new Image from imageData, which was previously obtained from a canvas element?


I\’ve searched for a solution, but they all seem to be drawing the result to a canvas.

So basically I need a way to convert an ImageData object to Image directly, if its possible.






Rating: 2 out of 5 based on 3 ratings



The post canvas – How to generate an Image from imageData in javascript? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/canvas-how-to-generate-an-image-from-imagedata-in-javascript.html

jquery – inside javascript string change html tag value

So, I\’ve got a string. The string contains html. I\’m checking the string for \’name\’, if it doesn\’t have one I\’m using sneaking one in there if it does I need to change what it is.



var myString = \'<input id=\"accountUser_c967817c993e62b1de50e4f0401a03ae\" type=\"hidden\" value=\"c967817c993e62b1de50e4f0401a03ae\" name=\"addRow[]\"><div class=\"colors goldbluegreenorange\"></div>\';
if (myString.indexOf(\'name\') == -1) {
myString = myString.substr(0,myString.indexOf(\'>\')) + \' name=\"addRow[]\"\' + myString.substr(myString.indexOf(\'>\'));
} else {
//get what\'s inside name\'s quotes and change it to removeRow[].
}


I\’ve got jquery going on too, if that makes more sense than straight javascript.






Rating: 2 out of 5 based on 5 ratings



The post jquery – inside javascript string change html tag value appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-inside-javascript-string-change-html-tag-value.html

jquery – Button – only do a postback if JavaScript function returns true

I have a button in ASP.NET. When the user clicks the button, I want to make some validation beforehand, so the postback only occurs if the validation method returns true.


My thought was to use the logic of the OnClientClick of the button. If you say OnClientClick=\”return false;\”, it won\’t give a postback, while returning true will. However, that\’s not working, as the resulting behaviour is it doesn\’t make a postback even though what my jQuery method returns.


Currently I have:


Markup:



<asp:Button runat=\"server\" ID=\"ReplyBtn\" OnClientClick=\"return ValidateInput();\" OnClick=\"ReplyBtn_Click\" CssClass=\"btn-large btn-success\"
Text=\"Answer\" />


JavaScript:



function ValidateInput() {
var value = stripHtml(CKEDITOR.instances[\'ReplyBox\'].getData()).trim();
var options = {
type: \"POST\",
url: \"../../Services/ForumOperationService.svc/ReplyToPostFeedback\",
data: \'{\"content\":\"\' + value + \'\"}\',
async: false,
contentType: \"application/json; charset=utf-8\",
dataType: \"json\",
success: function(msg) {
$(\"#StatusReplyLbl\").text(msg.ReplyToPostFeedbackResult);

if (msg.ReplyToPostFeedbackResult) {
return false;
} else {
return true;
}

},
error: function () {
return true;
}
};
$.ajax(options);
return false;
}

function stripHtml(str) {
return $(\'<div />\', { html: str }).text();
}


So basically, what\’s wrong with this code? And how can I perform validation on my button before making a postback?






Rating: 4 out of 5 based on 3 ratings



The post jquery – Button – only do a postback if JavaScript function returns true appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-button-only-do-a-postback-if-javascript-function-returns-true.html