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.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am working on a basic website and I'm trying to use JS to make "video-navigator"
The thing is:
my external script is not being included
So this is my HTML for including my JS
<script src="script.js"></script>
Click here for the entire site
You have a few issues with this. Firstly you're trying to set the innerHTML incorrectly which is failing. Secondly you're using a reserved word for a function (new). In the pop function I've commented out your incorrect bit and added a correct version. I've also renamed your function to new_renamed so that it works.
alert("working");
function pop()
{
alert("INVALID INPUT");
//HTMLDivElement("content") innerHTML = "";
document.getElementById('content').innerHTML = '';
}
function old()
{
alert("INVALID INPUT");
}
function new_renamed()
{
alert("INVALID INPUT");
}
Above will log.
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/
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/
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)
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
"Object doesn't support this property or method"
It's this line.
pthumb = $("#pthumb").attr("src");
Does anyone know why?
You have a javascript variable called "pthumb" and a DOM element with the id "pthumb", and IE's JS engine could be trying to use the wrong one.
If you have a function also called "pthumb" then IE could also be trying perform this action on the function object.
The last thing to try is to make sure you are using "var" when declaring "pthumb" in the Javascript. i.e.:
var pthumb = $("#pthumb").attr("src");
Are you ensuring the DOM is ready?
$(document).ready(function(){
//wrap your code in document-ready check
pthumb = $("#pthumb").attr("src");
});
you could double check the plain javascript method:
var jthumb= document.getElementById('pthumb').attributes['src'].value;
try{
pthumb = $("#pthumb").attr("src");
}
catch(er){
alert(er.message + '\n'+jthumb)
}
If you don't catch the error, the element is not yet ready.