Tuesday, August 28, 2012

javascript – Stop PHP with ajax

I have a JavaScript functions which calls a PHP function through ajax.

The PHP function has a set_time_limit(0) for his purposes.

Is there any way to stop that function when I want, for example with an html button event?






Rating: 1 out of 5 based on 4 ratings



The post javascript – Stop PHP with ajax appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-stop-php-with-ajax.html

How to multiply two colors in javascript?

The given parameters are r,g,b of two colors.


How can I multiply them? (Like blending mode->multiply in Photoshop)


Example:


color1:0,255,255


color2:255,255,0


multiplied:0,255,0


example






Rating: 1 out of 5 based on 4 ratings



The post How to multiply two colors in javascript? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/how-to-multiply-two-colors-in-javascript.html

pointers – Is it possible to have 2 variables pointing to the same object? (javascript)

I\’m trying to have both the variables \”my_a\” and letters.a point to the same object.



//i want letters.a to reference (point to) my_a, not be a copy...
//expected output should be: letters.a = c
//made variables into Objects.. but didn\'t help.

var my_a = new Object(\'a\');
var my_b = new Object(\'b\');
var letters = {\'a\': my_a, \'b\': my_b};

$(\'#output\').append(\'my_a = \' + my_a + \'<br>\');
$(\'#output\').append(\'leters.a = \' + letters.a + \'<br>\');

my_a = new Object(\'c\');

$(\'#output\').append(\'my_a = \' + my_a + \'<br>\');
$(\'#output\').append(\'letters.a = <span style=\"color:red\">\' + letters.a + \'</span>\');



See this fiddle:


http://jsfiddle.net/jCsUq/1/


But as you can see by the output, this is not working.


Any ideas? Is this possible with javascript?


Thank you.






Rating: 1 out of 5 based on 6 ratings



The post pointers – Is it possible to have 2 variables pointing to the same object? (javascript) appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/pointers-is-it-possible-to-have-2-variables-pointing-to-the-same-object-javascript.html

How to convert HTML to Javascript escapes in C#

I have converted a Hindi font to HTML code. Now what I want is to convert this HTML code to unicode escapes…


Hindi:



श्रीगंगानगर। हनुमानगढ़ मार्ग पर लालगढ़ जाटान छावनी के नजदीक शनिवार सुबह सड़क से पन्द्रह-...


Corresponding HTML:


श्रीगंगानगर। हनुमानगढ़ मार्ग पर लालगढ़ जाटान छावनी के नजदीक शनिवार सुबह सड़क से पन्द्रह-...


Now I want to convert this HTML code to unicode escapes like:



\\u0936\\u094D\\u0930\\u0940\\u0917\\u0902\\u0917\\u093E\\u0928\\u0917\\u0930\\u0964 \\u0939\\u0928\\u0941\\u092E\\u093E\\u0928\\u0917\\u0922\\u093C \\u092E\\u093E\\u0930\\u094D\\u0917 \\u092A\\u0930



Just like in this site. But I want this conversion through C# code, not in Javascript…






Rating: 5 out of 5 based on 4 ratings



The post How to convert HTML to Javascript escapes in C# appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/how-to-convert-html-to-javascript-escapes-in-c.html

How can i replace Space with %20 in javascript


Possible Duplicate:

jQuery / Javascript replace <space> in anchor link with %20



I am getting sParameter like this :


sParameter = document.getElementById(\'ddParameterType\').value;


If i am getting word like \"Test - Text\" as the ddParameterType item

then i am replacing the space in word like below:


sParameter = document.getElementById(\'ddParameterType\').value.replace(\"\",\"%20\");


but its returning a valur like %20Test - Text.

I need like Test%20-%20Text.


can anyone help.






Rating: 5 out of 5 based on 4 ratings



The post How can i replace Space with %20 in javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/how-can-i-replace-space-with-%20-in-javascript.html

JavaScript: function returning NAN

I\’m working on a codecademy.com lesson with instructions to write the calculateTotal function below. When I click run, it\’s returning NaN. Anyone know what\’s wrong with the calculateTotal function as I wrote it that\’s making it return NaN. Note, I understand that NaN means not a number…



// runner times
var carlos = [9.6,10.6,11.2,10.3,11.5];
var liu = [10.6,11.2,9.4,12.3,10.1];
var timothy = [12.2,11.8,12.5,10.9,11.1];

// declare your function calculateTotal here
var calculateTotal = function(raceTimes){
var totalTime;
for(i = 0; i < raceTimes.length; i++){
totalTime += raceTimes[i];
return totalTime;
}
};

var liuTotal = calculateTotal(liu);

console.log(liuTotal);


Note, many of the people answering this question have said that var totalTime has to be set to \”O\”. However, in the next codecademy lessson, the author writes a function with totalTime not set to anything and it works



var calculateAverage = function (raceTimes) {
var totalTime;
for ( i = 0; i < raceTimes.length; i++ ) {
totalTime = (totalTime || 0) + raceTimes[i];
}
// assign variable averageTime
var averageTime = totalTime / raceTimes.length;

return averageTime;
};






Rating: 5 out of 5 based on 3 ratings



The post JavaScript: function returning NAN appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-function-returning-nan.html

passing arguments from one function to another in javascript

I have date value



for(i=0;i<data[\'before\'].length;i++) {
var day = data[\'before\'][i];
var dte = new Date(day);


I am trying to display the dates as a link in a div dynamically from java script. On clicking the link I am passing dte as object to date_click function.



$(\'#before_dates\').append(\'<tr><td><a onclick=\"date_click(\'+dte+\');\" href=\"javascript:void(0)\">\'+dte.toDateString()+\'</a></td></tr>\');


On clicking the link the



function date_click(date){
alert(\"Hi...\"+dte);
}


I am getting following error:


Error: SyntaxError: missing ) after argument list

Source Code: date_click(Fri Aug 31 2012 00:00:00 GMT+0100 (IST));


I know its small error, but I could not figure a way to do that. Any help would be great.


Thank You






Rating: 1 out of 5 based on 3 ratings



The post passing arguments from one function to another in javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/passing-arguments-from-one-function-to-another-in-javascript.html

javascript – Fix positioning div by jquery / javscript only

As you may know, fixed positioning is not compatible in most mobile devices. As a workaround, I would like to fix-position a div using javascript (jquery would be nicer) with no position: fixed;


Any ideas?






Rating: 4 out of 5 based on 3 ratings



The post javascript – Fix positioning div by jquery / javscript only appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-fix-positioning-div-by-jquery-javscript-only.html

Passing value from inside of function to a parameter in JavaScript

I have a function that replaces characters from a string



function ratko(a) {
var k = a.toString();
var z = k.replace(/\\,/g, \'], [\');
var s = z.replace(/\\./g, \', \');
var final = \"[[\" + s + \"]]\";
alert(final);
}


What I need is to get the value of final outside the function like this:



var outsideValue = final;


EDIT!!! –


function ratko() gets it\’s value from ajax


success: function (data) {

if (data.success) {

alert(\”Note: This month has \” + data.holidays.length + \” holidays.\”);

praznici = data.holidays;

ratko(praznici);

}

else {

alert(data.ErrorMessage);

}






Rating: 3 out of 5 based on 5 ratings



The post Passing value from inside of function to a parameter in JavaScript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/passing-value-from-inside-of-function-to-a-parameter-in-javascript.html

javascript – Jquery UI Datepicker doesn't show again when link is clicked

I seem to have this working except for the fact that once the link is clicked, the datepicker opens, then I select a date and all is good and well, then once I try to click the link again, the date picker does not open again.


What am I doing wrong?



<html>

<head>

<!-- LOAD JQUERY LIBRARY: -->
<link href=\"jq/jquery-ui.css\" type=\"text/css\" rel=\"stylesheet\" />
<script src=\"jq/jquery.min.js\" type=\"text/javascript\"> </script>
<script src=\"jq/jquery-ui.min.js\" type=\"text/javascript\"> </script>

<script type=\"text/javascript\">

function test() {

var datePickerValue = null;

$(\"#d1\").datepicker().datepicker(\"show\").change(function ()
{
$(\'#d1\').datepicker({onSelect: datePickerValue = $(this).val() }).hide();

alert(\"You picked: \" + datePickerValue);
});



}


</script>



</head>

<body>

<div id=\"d1\"></div>
<a href=\"javascript:test()\">test</a>

</body>

</html>






Rating: 5 out of 5 based on 3 ratings



The post javascript – Jquery UI Datepicker doesn't show again when link is clicked appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-jquery-ui-datepicker-doesnt-show-again-when-link-is-clicked.html