JavaScript - Checkbox And Events
i have a checkbox:
Code: <input type="checkbox" id="my_checkbox" name="option2" value="Check" checked>Check i want to add an event to it so that i do something to a dom element when it is checked and when it is not checked.What is the event and how can i get its status? Similar TutorialsHi, This is my first time here so I hope I'm not posting to the wrong forum. If this has been answered before, please direct me to the corrent post. I've created several dynamic checkboxes with with following code: <code> var pnl = document.getElementById("pnlSalesPeople"); for (i = 0; i < sales.length; i++) { var ck = document.createElement("input"); ck.type = "checkbox"; ck.id = "ck" + i; //ck.checked = true; var label = document.createElement('label'); label.htmlFor = ck.id; label.id = "label" + i; label.appendChild(document.createTextNode(sales[i])); pnl.appendChild(ck); pnl.appendChild(label); pnl.appendChild(document.createElement('<br />')); } </code> All the checkboxes get put into the panel, one per line, as expected. However, clicking on any of them does not change their checked state--if I uncomment the line setting the state above, all the checkboxes are checked, but they don't become unchecked when clicking on them. I'm thinking I'm missing something that will make these checkboxes behave like they should or my approach to dynamic creation is flawed. In any event, my knowledge of Javascript is certainly not at expert level so I'm hoping there might a simple solution to my dilemma. Any help on this is genuinely appreciated. TIA I am using a freebie script that changes css elements using onClick when you hit a button. I have 12 choices I want to add, and don't want 12 buttons, but rather a dropdown list. 2 button examples (and js code) is: <input onclick="changecss('li','background','url(images/list_02.jpg) no-repeat 10.2em .12em')" value="Change to BG 2" type="button" /> <input onclick="changecss('li','background','url(images/list_03.jpg) no-repeat 10.2em .12em')" value="Change to BG 3" type="button" /> How do I convert this to a SELECT list?? Thank you! So here's what i want to do: i have 2 checkboxes, when Checkbox A is checked, i want to automatically check the checkbox B. When A is unchecked, then uncheck B how can i do that? thanks a lot ! i have a link that references: <a href="My_Video.asx">video</a>. when you click, video will open in the "windows media player" and the parent window goes blank. how can i prevent the parent window from going blank? thank you for help julio This is what I have: http://page-test.co.uk/js-test.html ..and it works exactly how I want it to, but I need it to work by doing these two things: (a) If you see in the change_button function, I have hard coded the 'name_can_vary' name element. I need to do it so this isn't hard coded (so it can work on any page/form). (b) I don't want to change any of the HTML, and I only want to change the code used in the change_button function (otherwise I will need to change many pages). Thanks in advance. Hi, If I have two check-boxes and one is already checked and then the is checked, how would I get it to uncheck the first one using JavaScript. Thanks, Cs1h Hi I have a requirement....I have a timer on a page. If the user leave the page (mouse goes off of that page) the timer starts and continues...and when the user comes into that page(mouse over that page) the timer goes off/STOP....Is this can be done?? using javascript??? pls help... hello, Im trying to write a program when the user clicks on the button, the textbox should display "how are you ". This is what I tried : <html> <head> <title>"Click"</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p> <input name="text1" type="text" id="text1" value="textbox 1" onFocus="this.style.background ='yellow'" onBlur="this.style.background='white'"> </p> <p> <input name="text2" type="text" id="text2" value="textbox 2" onFocus="this.style.background = 'yellow'" onBlur="this.style.background='white'"> </p> <p> <button onclick="textbox1.value="how are you">Click Me!</button> </p> </body> </html> Hi Guys I have been trying to implement a way of using `onclick` to fill out a form field, with a Value assigned by a clickable rollover image. So i have a image rollover of a PC, i give the PC a Value? ID? of `PC No34` When the image is clicked it updates its Value of PC No34 to a Form text field which is named `pcid` the Form is on the same page as the PC rollover image. I have been trying most of the day but not getting it. Pls help Thanks for any help with this Willo Hi guys, I'm a newbie so bear with me please. I downloaded this calendar which is now working great: JavaScript Calendar - Digital Christian Design (http://www.javascriptkit.com). Does anyone know how to change the date format from mm/dd/yyyy to dd/mm/yyyy? Also, is it possible to have links on such a calendar? I.e. in the event descriptions? Thanks. I sometimes see that some people use this expression: event = event || window.event Why people need to do this? What does it mean? With input box if you type something and refresh the page, the previous words that you typed in will be filtered and be display in a scroll down form in which you can click it. My question is, when I click the input type is it possible to scroll down, and display values that comes from a database? It should also filter the scroll down results. If it's possible I don't know how to do it. I tried googling but I can't find an explanation on how to do it. Thanks. <input type="text" value="" onclick=""> I was testing a required entry form, and i'm stuck. Code: <html> <head> <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(email,"Username must be filled out!")==false) {username.focus();return false;} } } </script> </head> <body> <form action="submit.htm" onsubmit="return validate_form(this)" method="post"> Username: <input type="text" name="username" size="20"> <input type="submit" value="Submit"> </form> </body> </html> i have this so far. i want to add a password part. i know i would take Code: Password: <input type="text" name="password" size="20"> and put it underneath the username part in the codes., but i don't know to do the rest, with the error message poping up. i have placed a text box with onclick and onblur event. onclick shows contents(links) of a div tag below it and onblur hides the div basically it was a jquery based drop down menu but due to some problem I need to avoid jquery. Now the problem happens when a link of div tag is clicked. The link does not work due to onblur event on the textbox. Any suggestion? Quote: <input type="text" style="text-transform: capitalize;" value="" class="abd_txtfld" name="loc" id="loc" onclick="gettabcontentSearch('','')" onblur="hide()"/> <div id="cityddsearch" class="select_citydd" style="position: absolute; margin-top: 2px; left: 5px; display: none;"> <ul> <li><a href='../link1.asp'>link1</a></li> <li><a href='../link2.asp'>link2</a></li> <li><a href='../link3.asp'>link3</a></li> </ul> </div> I am having trouble understanding why this does not work? Code: <HTML> <HEAD> <TITLE>Event Loops</TITLE> <SCRIPT TYPE="text/javascript"> function seturl(a,b,c,d,e) { this[0] = a; this[1] = b; this[2] = c; this[3] = d; this[4] = e; } function selectPage(list) { var page = Math.floor(Math.random()*4); winow.open(list[page],"Random_Page"); } choices = seturl("http://www.google.com, "http://www.yahoo.com, "http://www.youtube.com, "http://www.bing.com, "http://www.xbox.com"); </SCRIPT> </HEAD> <BODY onLoad="selectPage(choices);"> <H1>Please Wait...</H1> </BODY> </HTML> hi i am writing a code which needs multi event that's not my problem but it is about mouse event my html is like this Code: <form> d:<input type='text' name='dlink' id='dlink' onkeypress='a()'><br /> m:<input type='text' name='mlink' id='mlink'> </form> i want to perform any changes on dlink to mlink for example i'm using onkeypress so if a user used mouse [right click and then paste] it not works any event like onmouseover or onfocus or ... do not solve my problem i found out that IE has onpaste but other browser not so help me what should i do? Hi all, The question is hopefully relatively simple. if I have an object say Code: [ var SampleObject = function(id){ SampleObject.id = id; SampleObject.age= 22; } Is there a way to create an event that triggers every time the age member value changes? Thanks Ollie. Hi, I am trying to get this code to work in IE. It works on Firefox, but not on IE. Basically it blocks out scrolling the page down with space button, and registers up and down keys to run some code. The entire case statement including event registering and my code works completely fine in FF but it just won't work in IE (meaning that I can scroll down with space, and up and down with the up and down keys respectively). Here's the code, any help would be much appreciated. By the way I put this function in the HEAD section. Code: window.onkeydown = function(event) { // No space scrolling! switch (event.keyCode) { case 32: return false; break; case 38: { if (rB_Script.last_item <= 1000) { return; } else { rB_Script.focus_on_step(rB_Script.last_item - 1); } return false; break; } case 40: { if (rB_Script.last_item >= rB_Script.final_item) { return; } else if (rB_Script.last_item != -1) { rB_Script.focus_on_step(rB_Script.last_item + 1); } else { rB_Script.focus_on_step(1000); } return false; break; } } } Thank you very much! Hi, I am having a slight difficulty and hope someone can easily set me straight. I am trying to use the following code to track a button click and the second onclick event, the urchin tracking is not being completed but the first function is.... can someone please hopefully set me straight easily on the code? Many thanks Steve123. Code: <input type="submit" name="Submit" value="Buy Product" class="buy" onClick="document.form.submit();javascript:urchinTracker('/html/productdeals_button.asp')"> Hello. I'm new to JavaScript to any help in understanding would be great. For an html form, i'm am trying to have it so when a user clicks on the 'email' input box then a div element next to it displays "please make sure it's correct", and when they click out of the box (ie, to the next field), the message disappears again. I have managed to make it appear using this; Code: function displaymessage() { document.getElementById("message").innerHTML="please make sure your email address isn't fake.. you dick"; } <input class="textbox" name="email" onclick="displaymessage()"<input type='<p id="message"></p> BUT, how do i make it disappear when the user clicks out.. is it onchange()?.. if so, how. many thanks!! |