Is it possible upon page entry to modify this code to uncheck check box id LOTL even if the page is cached?
<script type="text/javascript">
function formReset()
{
document.getElementById("LOTL").reset();
}
</script>
You can use prop method:
$(document).ready(function(){
$('#LOTL').prop('checked', false);
// document.getElementById("LOTL").checked = false
})
This should do the trick:
$(document).ready(function()
{
$('#LOTL').attr('checked', false);
});
Is the LOTL element the checkbox or the form?
If it is the checkbox you might try this:
$( '#LOTL' ).removeAttr( 'checked' );
function formReset(){
document.getElementById("LOTL").checked = false;
}
Try this to uncheck
$(function() {
$('#LOTL').prop('checked', false);
});
Related
I have used the code:
<script type="text/javascript">
$(window).load(function () {
$(document).delegate(".checkall", "click", function(event) {
$(this).closest("table").find(':checkbox').attr('checked', this.checked);
});
});
</script>
This code is working fine when I select/deselect the checkbox in header for the first time. But when I again select the checkbox then this code is not working. The checkboxes are not selected.
You should use .prop() instead of .attr(). And you have to check if an element is already checked.
...
var $checkbox = $(this).closest("table").find(':checkbox');
if ($checkbox.is(':checked')) $checkbox.prop('checked', false);
else $checkbox.prop('checked', true);
...
I'm trying to hide an element if some specific value of input is not found on the site.
I can hide an element by:
$(document).ready(function() {
$("#someid").hide();
});
But how to show it, if the value is found? I'm trying to do something like this:
$(document).ready(function() {
$("#someid").hide();
$("input[value$='somevaluetobefound']").ready(function() {
$("#someid").show();
});
});
What am I doing wrong?
Try this:
$(document).ready(function() {
$("#someid").hide();
$('#inputID').on('input', function() {
if ( $('input').val() === 'test') {
$("#someid").show();
}
else $("#someid").hide();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Type 'test' to show DIV<br>
<input id="inputID" type="text">
<div id="someid">DIV</div>
I had not fully understood what you where trying to acomplish:
$( document ).ready(function() {
if (!$('input[value="somevaluetobefound"]'))
$("#someid").hide();
$(':input').on('keyup', function(){
if ($(this).val() == 'somevaluetobefound')
{
$("#someid").show();
} else {
$("#someid").hide();
}
});
});
I have updated the code here
EDIT: Based on new info provided by OP
$( document ).ready(function() {
if ($(':radio[value="somevaluetobefound"]').length !== 0)
$("#someid").show();
else
$("#someid").hide();
});
Sample here
<script type="text/javascript">
$(document).ready(function () {
$("input[value=somevaluetobefound]").closest('#someid').hide();
});
</script>
you can try this :
$(document).ready(function() {
$("#someid").hide();
if($("#someid").val() !=''){
$("#someid").show();
}
});
Improvising on #Arkej's answer:
$(document).ready(function() {
$("#someDiv").hide();
$(':input').on('input', function() {
if ( $('input').val() === 'somevalue') {
$("#someDiv").show();
}
else $("#someDiv").hide();
});
});
Here I am using :input to find all input boxes on the page. Since you need to either have an ID the input field you want or just have all input text boxes be used to show or hide your div depending on what the value you are looking for.
Also refer to this for guidance on getting val from inputs:
Get the value in an input text box
Cheers
I found this on one of the subjects:
http://jsfiddle.net/GHzfD/357/
I would like to ask how to alert(path) after choose the image from drop list.
<script>
$("body select").msDropDown();
alert(???)
</script>
Try this:
$(document).ready(function(){
$("body select").msDropDown();
$("#webmenu").change(function(){
alert($("#webmenu option:selected").attr('title'));
});
});
Working fiddle: http://jsfiddle.net/robertrozas/GHzfD/629/
Add an event handler to the msDropDown initialization parameters.
$("body select").msDropDown({
on: {
change: function(data, ui) {
alert(data.image);
}
}
});
Here: http://jsfiddle.net/GHzfD/630/
$("#webmenu").change(function(){
alert($(this).find("option:selected").attr("title"));
});
I wanna get selected id from my tabs. I tried anything but but I am very weak in javascript. This my tabs.
<li>Pondelok</li>
<li>Utorok</li>
<li>Streda</li>
<li>Štvrtok</li>
<li>Piatok</li>
<li>Sobota</li>
<li>Nedeľa</li>
This is my attempt, which return undefined.
<script>
var selected_tab = $(".ui-state-active").attr("id");
document.write(selected_tab);
</script>
this will alert id of tab on which you have clicked
$('.days').click(function(){
alert($(this).attr('id'));
});
if you want to write it on document use this
$('.days').click(function(){
document.write($(this).attr('id'));
});
Live Demo
http://jsfiddle.net/zgDYZ/
<script>
var selecId = "";
$('.days').click(function(){
selecId = $(this).attr('id');
});
</script>
Use selecId where ever you want..
Your are trying to to get attribute from class .ui-state-active which doesn't exist as per your markup. So your code wont work:
Try the below and this will work:
$(function() {
$("ul li").each(function() {
var selected_tab = $(this).find("a").attr("id");
alert(selected_tab);
})
});
<script type="text/javascript">
$(document).ready(function () {
$('.days').click(function () {
alert($(this).attr('id'));
});
});
</script>
another best way with validations
$('a.days').click(function(){
alert($(this).attr('id'));
});
I am using the code below where it toggles between 2 div's.
My problem is that I'm using a checkbox to trigger the toggle.
What I need is that...
If the checkbox is NOT check and the user checks it ... then it toggles but if the checkbox is already checked then do not toggle.
Is this possible at all?
Current code is below:
<script type="text/javascript">
$(function(){
$('.togglelink').click(function(){
$('#one').toggle();
$('#two').toggle();
});
});
</script>
What about adding that ?
$('.togglelink').click(function(){
if($(this).attr('checked')) {
return false;
}else{
$('#one').toggle();
$('#two').toggle();
}
});
<script type="text/javascript">
$(function(){
$('.togglelink').click(function(){ if (!($('.togglelink').attr('checked'))) {
$('#one').toggle();
$('#two').toggle();
}
});
});