Java script doesnt work [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am trying to learn javascript and I found an example but icant make it run What am i doing wrong
function CheckForPastDate(sender, args) {
selectedDate = sender._selectedDate;
var todayDate = new Date();
if (selectedDate.getDateOnly() < todayDate.getDateOnly()) {
sender.selectedDate = todayDate;
sender._textbox.set_Value(sender.selectedDate.format(sender._format));
alert("Wrong date!");
}
}

You made couple of mistakes in your code assuming that the code written is in javascript
Date comparisons need to be like this
if (selectedDate.getTime() < todayDate.getTime()) {
And you cannot format the dates in Javascript.
You can use the API available if you want.
Like the one I used MomentJS
sender._textbox.value = moment(sender.selectedDate).format(sender._format);
See my sample: http://jsfiddle.net/vinodgubbala/6MEG6/

Related

Explanation of macros in javascript from struct.js [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I know javascript but I don't understand the code in struct.js git repo. Does it use ES6? Can anyone explain the macros from that code and where can I find more information about it?
The code look like this:
let function = macro {
case { _ $id $args { $expr ... } } => {
var SP = makeIdent('SP', #{$name});
return withSyntax($SP = [SP]) {
return #{
function $id $args {
var $prevSP = $SP;
$expr ...
$SP = $prevSP;
}
}
}
}
}
That code don't work on Chromium (v. 30 on Xubuntu) I've also try to run it on node v0.10.22. Where can I test this code?
That code uses a preprocessor to convert from sweet.js to Javascript.
It's not bare Javascript.

In line error validation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a question and im not quite sure what would be the proper terminology.
I have a text box in a form.
When the use fills out some information i would like to check the text box and if there is an error show the error next to the textbox. An alert would work as will but prefer the in line error.
In case you are using jQuery here is some really basic validation:
$(function () {
$('#form').on('submit', function () {
var $input = $('#textbox');
// Make some validation againts the textbox here
if ('' === $input.text()) {
$input.after('<span class="error">Invalid value.</span>');
return false;
}
return true;
});
});
But as above pointed out, instead of reinventing the wheel look for some existing solution, for example the jquery validate plugin.

Is this eval Evil? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Writing a function in JavaScript. The plan is the function creates an object, which requires boolean statements as parameters. Something like this ->
var foo = new fuzz("pie < squirrel", "monkey === banana");
My question is - Is this evil?
*Note - * Inside the function 'fuzz' I will run checks on the values of the parameters. (Check string.length etc). I think this is how one is meant to use eval, it just has such a bad reputation on t'up web.
Thanks
Summing up the conclusions in the comments: write a simple rule evaluation engine! E.g.:
var variables = { ... };
function niceEval(condition) {
var operands = condition.match(/(\w+)\s+(\S+)\s+(\w+)/);
switch (operands[2]) {
case '<' :
return variables[operands[1]] < variables[operands[3]];
...
}
}
This also gives you a lot more control over possibly occurring errors than blindly evaling a string.

Improving code for learning purposes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have three tabs and I want to navigate when I click on each one of them. The code that I wrote is working just fine, but I believe that is bad coding, there is any way to improve this is just for learning purposes. Thanks!!!!
jQuery(".nuestra_actualidad li:eq(0)").click(function() {
jQuery("#tabs-actualidad").css("display","block");
jQuery("#tabs-articulos").css("display","none");
jQuery("#tabs-noticias").css("display","none");
});
jQuery(".nuestra_actualidad li:eq(1)").click(function() {
jQuery("#tabs-actualidad").css("display","none");
jQuery("#tabs-articulos").css("display","block");
jQuery("#tabs-noticias").css("display","none");
});
jQuery(".nuestra_actualidad li:eq(2)").click(function() {
jQuery("#tabs-actualidad").css("display","none");
jQuery("#tabs-articulos").css("display","none");
jQuery("#tabs-noticias").css("display","block");
});
Replacing jQuery with $ if possible (unless it clashes with another library) and then it can be reduced to a single function by utilising the index of the clicked element and calling the toggle function:
$(".nuestra_actualidad li").click(function() {
var index = $(this).index();
$("#tabs-actualidad").toggle(index === 0);
$("#tabs-articulos").toggle(index === 1);
$("#tabs-noticias").toggle(index === 2);
});
Example - http://jsfiddle.net/gSKeL/

Adding an id on to a href jquery [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get the id of an radiobutton to be added to href when the link is clicked. I tried searching google for a long time. But maybe i'm missing because it's very basic.
I do have a bit of code written but it doesn't work. Help?
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + ('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}
Looks like you've just forgotten a $:
... ('.aaasaff:radio:checked').attr('id')
should be
... $('.aaasaff:radio:checked').attr('id')
From what I can see the $ was missing.
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + $('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}

Categories

Resources