OK, beating my head against the Javascript/jQuery wall over here,
here is the code, which I simply can't get to work properly, any help is highly appreciated!
Especially this bugs me, changing row 60 from
c.gbForm.validator = c.dom.gbForm.validate(c.gbForm.validator); to
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
and row 61 from
c.dom.gbForm.unbind('submit').submit(c.gbForm.doAdd); to
$("#gbForm").unbind('submit').submit(c.gbForm.doAdd);
makes it kinda work, except then I get
this[0] is undefined error which I think is the jQuery validate plugin but I simply can't locate the exact spot at fault... So any hints/pointers to why the whole "var c" business isn't working and the same for the "this[0]" part would be awesome!
Thanks for any assistance!
John
Yes, here are a few things to look at
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
here you are referencing c.gbForm.validator before it is set (assuming this is the first assignment to c.gbForm.validator).
try this.
c.gbForm.validator = $("#gbForm");
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
also, why do you call c.doc.gbForm in one spot and just c.gbForm in another?
and as the comment says, validation should be as simple as $("gbForm").validate();
Related
I have been using the code on the following link for quite sometime and it works great however I now have a need to require a picklist selection from the list of values. My current picklist works fine so it is the "require" capability that I need help with:
http://www.mredkj.com/tutorials/tableaddrow.html
Can someone point me in the right direction? Thanks.
CG
It was not my intention to answer my own question but in case someone else stumbles across this post in the future the solution was simple but took a bit of trial and error.
Simply add the following line to the // select cell section:
sel.required = true;
Also make sure the first option contains no text in between the second set of single quotes
sel.options[0] = new Option('-SELECT-', '');
ok guys i have been working on these, this is like my main project and im pretty anxious about it, i have been practicing but im still a newbie. My code is like this and it does what it has to do, but im thinking that it could be improved to be better and more reusable, sorry to spam if i am, i already asked on the spanish version of the website with no satisfactory answer, im new to web developing and to this site, i always read the content on this site to answer my questions but for this time i didnt know how to exactly use the previous answers to fix my code, since im new to web developing and im trying to use jquery bit by bit. As i said my question is how can i create an array or a reg exp that does all the things this code does? without having to use .replace function all those times
i have tried urlencode function, and tried to iterate over arrays on jquery but i still dont know how to do it properly.
$( ".linkbestia" ).each(function() {
lnk = $(this).text();
enlace= $(this).attr("href");
espacios=lnk.replace(" ","_");
maslimpio=espacios.replace("'","%27");
muchomaslimpio=maslimpio.replace("(","%28");
muchomuchomaslimpio=maslimpio.replace(")","%29");
nuevoenlace=$(this).attr("href",enlace+muchomuchomaslimpio);
});
the actual output is for example codedquote'replaced space as i said it already does what it has to do, but i know it can be improved, i hope you guys help me since in my country these kind of questions cant be answered without a ton of difficulties
what it does right now:
what the user writes would look like this
the result would look like this
If I understand correctly you want to take href from below:
<a class="linknpc" href="url/in/url/url/The%27White_Mob">
and expected output is
The'White_Mob
after you get the href and lets say the var enlace looks like below.
var enlace = "url/in/url/url/The%27White_Mob"
Below will first use String split on '/' to get all sections from href and from resultant array get the last element by pop() and use decodeURIComponent to decode the encoded uri.
var ans = decodeURIComponent(enlace.split('/').pop())
ans would now have the value: The'White_Mob
note: If the href ends with '/' then you need to adjust above solution accordingly
Hei
I am going through the JavaScript tutorial on Codeacademy and I'm stuck on Introduction to Objects II lesson 2/30. The code that I have entered seems fine to me and the code prints the necessary line hello to the console.
But I get an error "Oops, try again. It looks like 'Hello!' wasn't logged to the console. Make sure that you properly defined the method and that you didn't change any of the provided code."
I cant seem to find anything wrong with this code that I have entered
function Person(job, married) {
this.job = job;
this.married = married;
// add a "speak" method to Person!
this.speak = function() {
console.log("Hello");
};
}
var user = new Person("Codecademy Student",false);
user.speak();
The problem is in your posted image, see the last line of the code editor:
user.speak();z //<-- z is not something what you have defined.
I went through several courses on Codeacademy. Codeacademy often has broken lessons, and if it's working on jsFiddle, it's likely two things.
1: Spelling and punctuation. Codeacademy is very specific with strings. One wrong letter, or one wrongly punctuated letter will show it as a fail.
2: Error. If this is the case, the codeacademy community usually has work arounds. If not, you can skip this particular lesson, and keep on going with the course. The 100% complete is more symbolic than anything else. As long as you're learning the concepts, it's find to skip whatever you have to.
Also, codeacademy has an excellent community that will give more specific advice tailored to the course. Here's the relevant forum for that course.
http://www.codecademy.com/forums/objects-ii/0
This seems so simple and I honestly can't see why this isn't working. Looked at other answers on here and mine still isn't working.
var randomArray = new Array();
randomArray[0] = 859;
alert(randomArray[0]);
How come nothing happens? It's probably an easy answer but I can't work it out.
Also, I'm trying to work out how to put a random number in the array so rather than putting 859 in index 0 lets say I want to put a random number between 1 and 20 in, so far I've got this but thats not working either
randomArray[1]=Math.floor(Math.random()*3);
EDIT: the .toString on alert seemed to fix it, thanks guys, knew it would be something small!
Is your javascript being referenced properly in a script tag with the correct type set?
<script type="text/javascript" ...> </script>
If not, it's fully possible your browser is simply ignoring it.
This is a wild guess, because your question doesn't contain enough information to know for sure, but make sure that your code is in a <script> block that looks like this:
<script>
// your code
</script>
Get rid of any "type" or "language" attribute on the tag; they're not needed and they're a source of error. If the "type" value is mispelled, then the browser will completely ignore the code.
Try calling .ToString() on your array property.
alert(randomArray[0].toString());
I'm very new to javascript, but I've managed to stitch the following together from different code-snippets, and forum-posts:
var s = document.createElement("script");
s.src = "http://service.somewebsite.com/?api-key=4P1k3y5R4w50m3";
document.getElementsByTagName("body")[0].appendChild(s);
However - it doesn't work.
The source-attribute is obviously not real (the service asked me to not share the API-key), but pasting the actual one into a browser, I get the excact script I want - with the right callback and everything.
I find it odd that this code doesn't work since the very similar
var i = document.createElement("img");
i.src = "http://i.imgur.com/TsCGbsy.jpg";
document.getElementsByTagName("body")[0].appendChild(i);
...executes just fine, when it takes its place. Is there something I don't know about changing the source of a script-element, or is there something else I've overlooked?
On a side note: I want to end up having "s.src" rely on some variables like the method, the api-key etc. (which is why I define it like this). If anyone has some other elegant solution to this, I'd be thankful as well. Any tips on syntax etc. are also very welcome.
Thanks in advance for any sort of help on this!
EDIT: I maybe should have mentioned that I'm trying to execute code from a source that consists of a JSON-object wrapped in a callback-function. The link itself works fine, and the function is executed properly when using
<script src = "http://service.somewebsite.com/?api-key=
k3y&callback=myFunction">
</script>
I'm basically attempting to do the same thing, only with (src) being stitched together from a string and one or more variables.
Try using setAttribute:
var s = document.createElement('script');
s.setAttribute("type","text/javascript");
s.setAttribute("src", "http://service.somewebsite.com/?api-key=4P1k3y5R4w50m3");