|
how do we create captcha with using Math.random() ?
|
|
|
|
|
Math.random() doesn't need to have anything to do with it. This really depends on the flavor of the month captcha that you are using.
I guess it is entirely possible if you are working with an existing captcha control that they are using Math.random() to seed it. In which case I would refer you to the docs.
If you are looking to create a captcha then I would recommend you do a search here on codeproject and use one of the articles that cover this as a basis for a starting point.
you want something inspirational??
|
|
|
|
|
I'm kind of new to web development...
It's such a soup of technology!
I'm currently working with ASP.NET MVC, jQuery,...
Anyhow, someone mentioned to me AngularJS[^]
How does it complement MVC? or web development in general?
What's your opinion on it?
|
|
|
|
|
AngularJs is an MVC implementation but not from the perspective of ASP.Net MVC like you are more familiar with.
more MVC client side (rendering) with a REST backend.
it is really popular with the Single Page application movement.
you want something inspirational??
|
|
|
|
|
I might give it a look anyway, just in case! ^^
|
|
|
|
|
I have a pagination page.At the first time, data and pagination links are generated from the server and shown them in my view.I have a drop down list.For every next time I want change the data and pagination links whenever dropdown list is changed without loading the page with jquery,ajax,json.I have successfully changed the data and links.I have created the pagination links as per first time server returns.But this time i can't trigger the ul>li>a element.I don't know why !!!.But the same js2 code works for the pagination which the server returns.
Html:server returns
<div class="pagination">
<ul>
<li class="disabled"><a >1</a></li>
<li><a href="http://localhost:8070/poralekha/home/universities/5">2</a></li>
</ul>
</div>
This works .
JS1:for pagination:
var pagination=" ";
pagination+="<ul >";
for(var i=1; i<=data['varsities'].length ;i++)
{
pagination+="<li class='disabled'>";
pagination+="<a href='#' class='page' >";
pagination+=i;
pagination+="</a>";
pagination+="</li>";
}
pagination+="</ul>";
$('.pagination').html(pagination );
here class='page' has been used for just get the value of i when .page is clicked
Js2:common for both pagination
$(".pagination > ul >li > a").click(function(event){
event.preventDefault();
alert("This index is clicked.");
});
or
$(".page").on('click', function(event){
event.preventDefault();
alert(" clicked.");
});
In short i want trigger when .page is clicked. I am just about to be mad with this.How can i solve this plz? Thanks.
modified 26-Jun-13 16:12pm.
|
|
|
|
|
I created the following from what you have written:
jsFiddle[^]
I don't see the problem that you are having?? Are you saying that you are getting a click event called for the static list and not the dynamic one that you are building??
Hopefully that jsFiddle will help some. You can edit and save your changes and then post back the new link if you want.
you want something inspirational??
|
|
|
|
|
Another homework assignment so please just let me know what direction I should go in.
Assignment details:
Function: counter
Parameter: An array of numbers
Returns: The numbers of negative elements, zeros, and values greater than zero in the given array.
Note: You must use a switch statement in the function.
My JS file:
var nums = new Array(-13,2,67,3,0,56,12,-41);
var len = nums.length;
for (i=0; i<len; i++) {
var count = nums[i];
}
var count = nums[i];
function counter() {
switch (count) {
case "negatives":
if (count < 0) {
document.write(count.length);
}
break;
case "zeros":
if (count == 0) {
document.write(count.length);
}
break;
case "positives":
if (count > 0) {
document.write(count.length);
}
break;
default: {
document.write("nothing!");
}
}};
I am not sure where to go with this one. I know it's the switch statement that throwing me off and I am not sure if my statement for counting each variable is necessarily correct either but I feel like I'm somewhere in the correct thinking here.
|
|
|
|
|
loop through the array and use switch on each element to increment the number of negative, zero and positive values..hope this helps..
|
|
|
|
|
You have all the parts but need to rework them a bit. I can't see how your calling the function but how about you pass the calculate function the array and then do your foreach with in the loop.
In the end you'll want to keep track of each element individually so you can properlly account for them. Currenlty your just doing a document.write but that could also be for debugging purposes.
Good Luck!
|
|
|
|
|
Use the sign function the values of which you can use in your switch statement:
var nums = new Array(-13,2,67,3,0,56,12,-41);
var len = nums.length;
var positives = 0;
var negatives = 0;
var zeroes = 0;
for (i=0; i<len; i++) {
counter(num[i];
}
function counter(number) {
var sign = (number > 0) ? 1 : (number < 0) ? -1 : 0;
switch (sign) {
case 1:
positives++
break;
case 0:
zeroes++;
break;
case -1:
negatives++;
break;
};
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
I am currently a college student so please be kind to me being a novice! I am working on an assignment and I just can't figure out where I am going wrong.
Assignment Details:
Function: tst_name
Parameter: A string.
Returns: true if the given string has the form
String1, String2 letter
where both strings must be all lowercase letter except for the first letter and letter must be uppercase; false otherwise
My JavaScript file:
function tst_name(name) {
var ok = name.search(/^[A-Z][a-z]+, [A-Z][a-z]+, [A-Z]\.?$/);
if (ok == 0) {
return true;
} else {
return false;
}
}
var tst = tst_name(Woods, Trista, M);
if (tst) {
document.write("Program error <br />");
} else {
document.write("Valid name. <br />");
}
var tst = tst_name(woods, trista, m);
if (tst) {
document.write("Invalid name <br />");
} else {
document.write("Program error <br />")
}
My HTML file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html lang="en">
<head>
<title>Woods | Test Name | Exercise 4.12</title>
<script type="text/javascript" src="exercise4-12.js">
</script>
</head>
<body>
<script>
document.write("Woods, Trista, M: " + tst + "<br />");
document.write("woods, trista, m: " + tst + "<br />");
</script>
</body>
</html>
When I view this in a browser it just shows:
Woods, Trista, M: undefined
woods, trista, m: undefined
So I'm just confused. I followed an example in our book and I just don't know what I need to do in order to get the variables to write the correct statements in my HTML document.
|
|
|
|
|
Your test script is attempting to pass three variables (which don't exist) named Woods, Trista and M. Ditto for the lower case as well.
surround them with quotes. "Woods, Trista M"
|
|
|
|
|
Oh geez! It's always the simple things that screw me up. I also noticed I was missing a semicolon after one of my statements too.
Thanks for helping a beginner out!
|
|
|
|
|
tristarterror wrote: Thanks for helping a beginner out!
No problem.
Semicolons in javascript are a bit of a nuisance because there are some nasty surprises with return statements in particular.
Two books you definitely ought to have handy. Javascript the Definitive Guide 5th edition (O'Reilly), and Douglas Crockford's Javascript The Good Parts (O'Reilly).
The language is a b*stard of a mess. Even the original 'official' language specification is crap.
|
|
|
|
|
hi experts, i need help about skype in my webpage.
i have a textbox client-side, in the webpage
<input type="text" id="phoneSkype_ws" />
<input type="button" onclick="return call();" value="Call!" />
when i click on call button, i need to call by skype, the same number in the textbox, but i don't know how!!!
with the following code, i'm not able to do this
<div id="skypeButton">
<script type="text/javascript">
var num = $("#telefono").val();
Skype.ui({
"name": "call",
"element": "skypeButton",
"participants": ????,
"imageSize": 32
});
</script>
</div>
hope someone can help me!!
|
|
|
|
|
the new windows 8 msn site (t.msn[^] has links that depress on mouse-down. Does anyone know how I can get source javascript that achieves the same effect?
TIA
bart
|
|
|
|
|
I think you could have the same effect by applying the CSS pseudo-class for the anchor.
Below is the example from W3Schools
a:link {color:#FF0000;}
a:visited {color:#00FF00;}
a:hover {color:#FF00FF;}
a:active {color:#0000FF;}
active defines the effect on mouse down event.
|
|
|
|
|
Oh, thanks. Its actually the way the link is depressed that I was interested in..
bart
|
|
|
|
|
i have problem to display info of google maps, when click in outside of map. but if inside of map when i click a marker, info of google maps can display.
function onload() {
var st=getURLParameters("man");
var kd_link=getURLParameters("kd");
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
var dt="";
xmlhttp.open("GET","hasil.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var tbl=xmlDoc.documentElement.getElementsByTagName('page');
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(-7.8711188835883945, 112.52471923828125),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var gmarkers=[];
var marker, i;
function Linkclicked(i) {
GEvent.trigger(gmarkers[i], "click");
}
var kde;var nm;var l1;var l2;var bk;
for (i = 0; i < tbl.length; i++) {
kde=xmlDoc.getElementsByTagName("kode")[i].childNodes[0].nodeValue;
nm=xmlDoc.getElementsByTagName("nama")[i].childNodes[0].nodeValue;
l1=xmlDoc.getElementsByTagName("lat")[i].childNodes[0].nodeValue;
l2=xmlDoc.getElementsByTagName("long")[i].childNodes[0].nodeValue;
bk=xmlDoc.getElementsByTagName("bk")[i].childNodes[0].nodeValue;
marker = new google.maps.Marker({
position: new google.maps.LatLng(l1, l2),animation:an, icon:bk,map: map
});
google.maps.event.addListener(marker, 'click',(function(marker, i) {
return function() {
infowindow.setContent(xmlDoc.getElementsByTagName("nama")[i].childNodes[0].nodeValue);
infowindow.open(map, marker);
}
})(marker, i));
gmarkers[i]=marker;
}
}
that's my code, when i try to call one of the google maps info marker .
<a href="javascript:Linkclicked('0')">try</a>
it couldn't be displayed... please give me solution??
|
|
|
|
|
|
thanks i had solution about this. i used trigger at google maps.
|
|
|
|
|
I wrote this script some time ago, it works fine on PC's, but on mobile devices, I need to optimize it and get it to run faster in speed.
So like on a iPhone 4, it takes about 3 seconds to run.on a PC it takes 1 second, which is slow.
Just looking for ideas or tips, or another set of eyes to check it out.
1. Confirms a value in the textbox, if not, textbox turns pink, and the error arrow shows
2. checks if it's a number
3. increments value.
function jquery_Add2Cart_Numeric_Up() {
var vFlag = true;
var txtFocus = $('[id*="_txt_Focus_Field"]').val();
var txtError = $('[id*="_txt_Error_Field"]').val();
var qty_value = $('[id*="_txt_Modal_Add2Cart_SelectQty"]').val();
if (qty_value.length < 1) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtError);
vFlag = false;
}
else if (qty_value.length > 0) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtFocus);
var re_Qty = new RegExp("^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$")
var txt_Qty = $('[id*="_txt_Modal_Add2Cart_SelectQty"]').val();
var match_Qty = re_Qty.exec(txt_Qty);
if (match_Qty == null) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtError);
$('[id*="_lbl_Modal_Add2Cart_Center_Container_QtyMessage"]').text("Invalid Quantity!");
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').val("1");
vFlag = false;
}
else if (match_Qty !== null) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtFocus).show();
$('[id*="_lbl_Modal_Add2Cart_Center_Container_QtyMessage"]').text("Select your quantity:");
var qty = parseInt($('[id*="_txt_Modal_Add2Cart_SelectQty"]').val());
if (qty < 1000) {
qty ++
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').val(qty);
}
}
}
return false;
}
|
|
|
|
|
Jeepers, in 6-7 secs on a 650Mhz android phone, I can generate an image thats 256x256, with 2 calls to _each_ of square root, sin and cos - perPixel.
Something I notice is that you've got many instances of $('[id*="_txt_Modal_Add2Cart_SelectQty"]') in your code. I'd try just evaluating that statement once, before then using it later - much like you did for the css rules.
I dont jQuery, I apologise if the syntax is incorrect.
In any case,the point is - evaluate expensive things as few times as possible.
In my code, this could be done by pre-computing sin cos and sqrt tables. In yours I'd assume you could evaluate the statement I've mentioned. I expect it takes jQuery some time to parse the statement before finding the element that you wish to target.
I.e
var txtModalSelectQtyEl = $('[id*="_txt_Modal_Add2Cart_SelectQty"]');
...
...
var qty_value = txtModalSelectQtyEl.val();
...
...
txtModalSelectQtyEl.css('background-color', txtFocus);
..
..
Make it work. Then do it better - Andrei Straut
|
|
|
|
|
I didn't notice the numerous calls to the qty textbox.
What I did think of, is that perhaps I should just assume that the value is correct or an integer, and if not, then run the rest of the script. It's really fast now, and does not hesitate anymore.
On the iPhone, it was a matter of making the increment buttons bigger for a more positive contact with the finger or thumb.
Did I mention that it's just a webpage running on a phone?
Love the feedback though, this function has been giving me trouble for quite a while now, if you think my new idea is bad, just let me know.
[Edit]
Hey Eric, just saw your name on the post. Let me know what you think of the new design below, if it sucks, please let me know so I can work on it again. Thanks Jim
function jquery_Add2Cart_Numeric_Up() {
try {
var qty = parseInt($('[id*="_txt_Modal_Add2Cart_SelectQty"]').val());
if (qty < 1000) {
qty++;
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').val(qty);
}
}
catch (err) {
var vFlag = true;
var txtFocus = $('[id*="_txt_Focus_Field"]').val();
var txtError = $('[id*="_txt_Error_Field"]').val();
var qty_value = $('[id*="_txt_Modal_Add2Cart_SelectQty"]').val();
if (qty_value.length < 1) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtError);
vFlag = false;
}
else if (qty_value.length > 0) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtFocus);
var re_Qty = new RegExp("^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$")
var txt_Qty = $('[id*="_txt_Modal_Add2Cart_SelectQty"]').val();
var match_Qty = re_Qty.exec(txt_Qty);
if (match_Qty == null) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtError);
$('[id*="_lbl_Modal_Add2Cart_Center_Container_QtyMessage"]').text("Invalid Quantity!");
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').val("1");
vFlag = false;
}
else if (match_Qty !== null) {
$('[id*="_txt_Modal_Add2Cart_SelectQty"]').css('background-color', txtFocus).show();
$('[id*="_lbl_Modal_Add2Cart_Center_Container_QtyMessage"]').text("Select your quantity:");
}
}
}
return false;
}
|
|
|
|
|