I'm trying to complete some homework and it appears the book might have gotten it wrong. I have a simple html page that allows user to pick a credit card in our case american express. The user then enters a number and evalutes that number based on a regular expression. My question ends up being when test() evaluates the number it returns a boolean or a string? I should then compare that string or boolean? True == true should fire off the code in a nested if statement. Heres what the book gives me as valid code:
if(document.forms[0].cardName.value == "American Express")
{
var cardProtocol = new RegExp("^3[47][0-9]{13}$"); //REGEX ENTRY HERE
if(cardProtocol.test(document.forms[0].cardNumber.value))
document.forms[0].ccResult.value = "Valid credit card number";
}
The above code doesn't work in firefox. I've tried modifying it with 2 alerts to make sure the number is good and the boolean is good...and still no luck:
if(document.forms[0].cardName.value == "American Express")
{
var cardProtocol = new RegExp("^3[47][0-9]{13}$"); //REGEX ENTRY HERE <------
alert(document.forms[0].cardNumber.value)
alert(cardProtocol.test(document.forms[0].cardNumber.value))
if((cardProtocol.test(document.forms[0].cardNumber.value)) == true ) // <--Problem
{
document.forms[0].ccResult.value = "Valid credit card number";
}
else
{
document.forms[0].ccResult.value = "Invalid credit card number";
}
}
Any ideas? the if loop is the culprit but I'm not figuring out why it is not working. Please throw up the code for the if loop! Thanks for the help!
I'm trying to create a site with 2 slideshows. I've tweaked and re-tweaked the JS and Jquery numerous times. Sometimes one slideshow works perfectly and the other cycles between one picture, other times both work but are out of sync, or the fadeIn doesn't seem to be applied to the second slideshow, or in some variations one slideshow stays frozen on the initial image and just remains static. Anyway, I created a JS Fiddle (link at bottom) and apparently my code is at least free of typos. JS is below, the rest is on the JS Fiddle. Any help would be greatly appreciated.
$(document).ready(function () {
$(".slider #1").fadeIn(1000);
$(".slider #1").delay(2000).fadeOut(1000);
var sc = $(".slider img").size();
var count = 2;
setInterval(function () {
$(".slider #" + count).fadeIn(1000);
$(".slider #" + count).delay(2000).fadeOut(1000);
if (count === sc) {
count = 1;
} else {
count++;
}
}, 3500);
$(".sliderTwo #7").fadeIn(1000);
$(".sliderTwo #7").delay(2000).fadeOut(1000);
var sc2 = 12;
var count2 = 7;
setInterval(function () {
$(".sliderTwo #" + count2).fadeIn(1000);
$(".sliderTwo #" + count2).delay(2000).fadeOut(1000);
if (count2 === sc2) {
count2 = 7;
} else {
count2++;
}
}, 3500);
});
http://jsfiddle.net/gg4PL/
I have that :
<div data-role="page" id="Home">
<div data-role="header" >
<h2 class="header">My app</h2>
</div>
<div data-role="content">
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="partials/home.html" data-icon="home" data-transition="slide">Home</a></li>
<li><a href="partials/about.html" data-icon="info">About</a></li>
</ul>
</div>
</div>
</div>
</body>
I want when a users click on links le content slide on a div content of for exemple home.html who have just that :
home
that is possible or not ?
Thanks :)
In my JSP page I am using post method while submitting the page.
So once I go from Page 1 to page 2. In Page 2, If I press F5 I am getting alert as
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
I knew this question is a bit sarcastic but please give me an Idea.
I can't change my method from POST to GET because I need to send large amount of data.
Thanks in advance...
Edited:
In my Page1.JSP I call onClick function in that function I call action as "/page2servlet.do".
Now, In Java side I use Spring Framework. With MVC Object I return to page2.jsp.
So where do the response.sendRedirect Fit.
So I've seen things like WordPress and FCKEditor, and basically a bunch of stuff that uses external code that I can't see or edit. Whenever I ask about editing and saving the content of a page in real time I just get referenced to an API or I get handed code that only changes the page until it's reloaded.
What I want to know is how do I code it myself? I want to add real time content editing to a page without the use of someone else's code. I've checked out code for various forums and wikipedia and whatnot, and all of it references code I don't have access to.
Is this a thing? Can I edit a page in real time? I thought of writing the edited text to a file on the server, and then when they click save, reading it back into the code to the section they were editing, but I don't know how to do that or if it's even possible.
As a side note, I'm very new to html, but not new to coding.
EDIT: The structure can be very much like Wikipedia, it doesn't have to be real time, it just has to work
$('<a />').attr({
'href': '#'
})
.append(
$('<img />').attr({
'id' : 'img',
'src' : 'edit.png'
}))
.appendTo('body');
Is the the "right way" to go about adding <a href="#"><img src="edit.png" id="img" /></a> to the body?
Also how would I add some css onto the img?
I put some jquery in my website that makes the text move to the right when the page changes. It works in Firefox and Safari but it doesn't work in Internet Explorer. My url to my website: http://katieduck.com/Courses/Improvisation%20Winter%20Course%20Dartington.html
Here is the code that is not working:
$(document).ready(function() {
$('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
$('#featuredvid > ul').tabs();
});
Maybe you can find out what is wrong.
I have created a html page in php and upon submission i validates that page using PHP. After validating i want to show an alert msg to show its status like showing any greeting or request for re-enter.
I have dont validation. Now i m using
header( 'Location: http://localhost/assignment/WebForm.htm' ) ;
to redirect user to same page but with a alert msg at page load or something like that. What I need to do ?
hi all,
I'm using jQuery to parse some XML, like so:
function enumOptions(xml) {
$(xml).find("animal").each(function(){
alert($(this).text());
});
}
enumOptions("<root><animal>cow</animal><animal>squirrel</animal></root>");
This works great. However if I try and look for nodes called "option" then it doesn't work:
function enumOptions(xml) {
$(xml).find("option").each(function(){
alert($(this).text());
});
}
enumOptions("<root><option>cow</option><option>squirrel</option></root>");
There's no error, just nothing gets alerted, as if the find isn't finding anything. It only does it for nodes called option everything else I tested works ok!
I'm using the current version of jQuery - 1.4.2.
Anyone any idea?
TIA.
bg
now i get the image's width and height when onload function of img . my problem is, the image original width = 500px but document.getElementId(id).offsetWidth gives only 300px and also for height. Please help me how can i get original width and height of image
Hi,
I need to be able to provide a page for the end user where thay can search in the following :
Search work
Category
Price
AdType
Location
and so on.
Its important that the user can copy the url and then use it later(and get the same settings). Its also important to be able to save these settings on the user in the database.
So far I have created a ModelView class that contains the parameters but I am not sure that this is the right way to go? Maby I should pass all inte the URL.
If so, how do I accomplish this? Is there any samples I could look at?
BestRegards
To empty a div and replace it with an image I am using:
$(this).html('');
$('<img/>', {
src: 'blah.gif'
}).appendTo(this);
Is there a better way to do this?
I have created my entire website by using a main table, and having the content inside the table.
Some ppl suggest this is wrong, and I would like to know what to do specifically in my situation.
On my index.html I have a <table align="center"> and then all content in it.
Now the content is in form of DIVS and they all have relative positioning, so they are relative to the table.
For example:
<table align="center">
<tr>
<td>
<div style="position:relative; left:14px; top:50px;">
CONTENT HERE... (Form, divs, images)
</div>
</td>
</tr>
</table>
I have just gotten to the stage of browser compatibility.
Without making any changes whatsoever, my website works perfect in FF, SAFARI, Chrome and Opera. Only trouble with IE.
So for my Q, if you where me, would you change my layout and remove the tables, and instead use alot more css and alot more DIVS, or would you go with what I have?
And please if you answer me, don't just provide me with the answer, but also a "why" that is... in other words, give me arguments and facts...
Thanks
{"paging": {"pageNum":2,"action":"Next","type":"","availableCacheName":"getAllFunds","selectedCacheName":"","showFrom":101,"showTo":200,"totalRec":289,"pageSize":100},
"Data":[{"sourceCodeId":0,"radio_fund":"individua
l","availableFunds":[],"fundId":288,"searchName":[],"fundName":"Asian Equity Fund A Class Income","srcFundGrpId":"PGI","firstElement":0,"las
tElement":0,"totalElements":0,"pageList":[],"standardExtract":true}]
I have json file with above format with two fileds,one paging and one is Data array.
I able to retrieve values of paging,but i am not able to retrieve the values of data array with .each function of jquery.
Any suggestions or inputs really appreciated.
I have a jquery variable which has is showing the value in the console as ..
["INCOMING", 0, "INETCALL", 0, "ISD", 31.8, "LOCAL", 197.92, "STD", 73.2]
Now as per my need i have to break these values and make it like this
["INCOMING", 0],["INETCALL", 0],["ISD", 31.8],["LOCAL", 197.92],["STD", 73.2]
but these values i need to make in the required formate dynamically as this is received from
database.
Here is my ajax call to get the values from server side..
var dbdata="";
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'getPieChartdata',
async:false,
dataType: "text",
success: function(data) {
dbdata=JSON.parse(data);
}
});
console.log(dbdata);
});
Please guys help me .
Thanks in advance..
When I am trying to access Topspeed.com, my internet explorer shows the page just fine, but if I try firefox then I end up on the apache 2 test page... any idea why ?
I have everything in place to create slugs from titles, but there is one issue. My RegEx replaces spaces with hyphens. But when a user types "Hi there" (multiple spaces) the slug ends up as "Hi-----there". When really it should be "Hi-there".
Should I create the regular expression so that it only replaces a space when there is a character either side?
Or is there an easier way to do this?
For instance this code:
function stuff() {
this.onlyMethod = function () {
return something;
}
}
// some error is thrown
stuff().nonExistant();
Is there a way to do something like PHP's __call as a fallback from inside the object?
function stuff() {
this.onlyMethod = function () {
return something;
}
this.__call__ = function (name, params) {
alert(name + " can't be called.");
}
}
// would then raise the alert "nonExistant can't be called".
stuff().nonExistant();
I'm trying to prevent certain keys from being entered into an input box, but only if that particular key is pressed whilst the shift key is held:
$('selector').keydown(function(e) {
console.log(e.shiftKey);
if (e.shiftKey && e.which == 51) {
e.preventDefault();
alert('Disallowed');
}
});
The alert fires but the character still appears in the text box. If I remove e.shiftKey from the if statement and press the key (without shift held), the alert fires and the character does not appear in the text box.
I've tried searching around for an explanation as to why this happens but to no avail, any help would be greatly appreciated!
edit
Removing the alert seems to fix the problem (which seems bizarre), I'd really love to know why it behaves in this way though, it doesn't seem to make any sense.
Thanks
Hello again,
I'm trying to loop through my totals in order to get a grand total for my web app. So far the code I am working with is the following:
function calcAllFields() {
var name = parseFloat($('div [name = total[]]').text());
var totArray = $.makeArray(name);
var total = 0;
for (var i = 0; i < totArray.length; i++) {
total += totArray[i];
}
$("#target1").text(total);
}
Instead of adding integers, something is being read as a string. Say I want to add 200 + 50, instead of 250 I get 20050. Could anyone please point out what I'm doing wrong? Thanks!
Hey guys,
I'm showing up veeeery long URLs in my Safari extension. Obviously, they can't fit on a single line. Currently, word breaking rules make it so most URLs are on two lines: the first one is rather short and ends with the ? symbol, and the other is ridiculously long and contains all the rest of the GET parameters.
I'd like to make it so words also break on the & symbol, without screwing up copy-paste if possible. I've tried to replace every & with &\u00ad (& + the soft hyphen character), but it's kind of weird to see the hyphen after the & when there really isn't any in the URL.
I thought there was something in store with CSS3 for that kind of problem, but I can't find it.
Any suggestion welcome, as long as it works with Safari.