JavaScript - Help Me About Elementbyid And Button Id
this is javascript
document.getElementById("times").value=hours+":"+mins+":"+secs; if(timeral==true && hours==hvb && mins==mvb && secs==svb){ document.getElementById("onbtn").click(); } document.getElementById("times1").value=hours+":"+mins+":"+secs; if(timeral1==true && hours==hv && mins==mv && secs==sv){ document.getElementById("offbtn").click() ; } //////*****THIS FOR CHANGE IMAGE ******////// function corridoroff(){ document.getElementById("nyala").src="level2.jpg"; } function corridoron(){ document.getElementById("nyala").src="level2on.jpg"; } this is html <img id="nyala" src="level2.jpg" width="765" height="398" /> <input type="button" name="manualoff" id="onbtn" value="Manual OFF" onClick="do_portcontrol(1,0);corridoroff(); return false;"></td> <input type="button" name="manualon" id="offbtn" value="Manual ON" onClick="do_portcontrol(1,1);corridoron(); return false;"></td> **MY PROBLEM IS....how to put the id"nyala" into this button?? 2 elementbyid into one button? Similar TutorialsHey. I've got some code that shows a div if a link is clicked. How can I add to the code so when it's clicked again, it hides it. Here's my code (the .linkon class needs to be removed again after as well): Code: <style type="text/css"> .linkoff-div .linkon { color:orange; font-size:15px; font-weight: bold; } .linkoff-div { text-align: left; line-height: 20px; border-bottom: 2px solid #344050; margin-top: 15px; } .linkoff-div a { color:white; font-size: 15px; } #faq1 { background-color: #596778; width: 540px; padding: 5px; } </style> <script type="text/javascript"> function hideall(){ document.getElementById("faq1").style.display="none"; document.getElementById("faq2").style.display="none"; document.getElementById("faq3").style.display="none"; document.getElementById("faq4").style.display="none"; document.getElementById("link1").className="linkoff"; document.getElementById("link2").className="linkoff"; document.getElementById("link3").className="linkoff"; document.getElementById("link4").className="linkoff"; } function myclick(id){ hideall(); document.getElementById("faq" + id).style.display="block"; document.getElementById("link" + id).className="linkon"; } </script> <div class="linkoff-div"><a href='#' id="link1" onclick="myclick(1);return false;" class="linkoff">Registration</a></div> <div id="faq1" style="display:none"> Registration stuff </div> <div class="linkoff-div"><a href='#' id="link2" onclick="myclick(2);return false;" class="linkoff">Logging In</a></div> <div id="faq2" style="display:none"> Logging in stuff </div> <div class="linkoff-div"><a href='#' id="link3" onclick="myclick(3);return false;" class="linkoff">My Account</a></div> <div id="faq3" style="display:none"> My Acccount stuff </div> <div class="linkoff-div"><a href='#' id="link4" onclick="myclick(3);return false;" class="linkoff">Videos</a></div> <div id="faq4" style="display:none"> Video stuff </div> Thanks, Adam Below are the full Javascript and HTML to detect a browser and either display HTML5 or Flash video. However, the script is returning an error, 'document.getElementById(...)' is null or not an object. Any suggestions? Code: var deviceAgent = navigator.userAgent.toLowerCase(); $brwzr = deviceAgent.match(/(chrome|firefox|safari|msie 9.0)/); if ($brwzr) { document.getElementById("video_5").setAttribute("class", "on"); } else { document.getElementById("video_F").setAttribute("class", "on"); } Code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Video Switch</title> <script language="JavaScript" src="index/js/detect.js"></script> <style> <!-- .off { display: none; } .on { display: inline; } --> </style> </head> <body> <div id="video_5" class="off">HTML5!</div> <div id="video_F" class="off">Flash!</div> </body> </html> Hey guys. This is vague because I dont know what exactly to tell you but please reply with me so I can fix this. I want to add something to my forum. Specifically, I want to add a HTML and Picture button for when you go to reply. Like posting an article here, there are also these options (font, alignment, insert image) I do not know how to achieve this but shouldnt be too hard. Here are the two sources you will need to look through to help me fix the forum. http://neoweather.com/FWFORUM.JS http://static.websimages.com/JS/fw.js THANKS Hey guys. I want to add something to my forum. Specifically, I want to add a HTML and Picture button for when you go to reply. Like posting an article here, there are also these options (font, alignment, insert image) I do not know how to achieve this but shouldnt be too hard. Here are the two sources you will need to look through to help me fix the forum. http://neoweather.com/FWFORUM.JS http://static.websimages.com/JS/fw.js THANKS i'm still a relative noob and this has me stuck - i have a save button with a "save as copy" in the save dropdown list. add new item directs to a premade/formatted project that is used as a template, so on that item i only want/need the "save as copy" but on all other items that use the form i need to only have the "save" function. is there any way to either change the function of the button depending on item that is being viewed in the edit screen OR hide the "save" button and only show the button associated with "save as copy - and vis versa for the rest of the items?? current button code is - protected function getToolbar() { $options = array(); $user = JFactory::getUser(); $create_ms = $user->authorise('core.create', 'com_pfmilestones'); $create_task = $user->authorise('core.create', 'com_pftasks'); $options[] = array( 'text' => 'JSAVE', 'task' => $this->getName() . '.save'); $options[] = array( 'text' => 'Save as new project', 'task' => $this->getName() . '.save2copy', 'options' => array('access' => ($this->item->id > 0))); PFToolbar::dropdownButton($options, array('icon' => 'icon-white icon-ok')); item used as template is id=8 any help or suggestions would be greatly appreciated.. Hi, I am not entirely sure what I am doing wrong here, and I have been looking at this for ages, so apologies in advance if I have become so bleary eyed I can't see something simple. I use php to create buttons based on values pulled for a table. The problem I have is when you click on the first button the javascript function works great, when you click on the next button you get the same output even though it should be different results. I am working in ff and I can see on my firebug console that the javascript function is being called, but it is not passing the new value of the second or third button, it just keeps repassing the value of the first button. So not entirely sure where I am going wrong here. My page is: Code: <script type="text/javascript"> function loadXMLDoc2(File,ID,Msg){ if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; } } var params=Msg; xmlhttp.open("POST",File,true); xmlhttp.setRequestHeader("Pragma", "Cache-Control:no-cache"); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </script> <head> <body> <?php $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $result = mysql_query("SELECT DISTINCT theme FROM goods WHERE category='{$_POST['category']}' ORDER BY theme DESC"); while($row = mysql_fetch_array($result)){ echo '<input type="text" class="hidden" name="theme" id="theme" value="' . $row['theme'] . '" ><input type="button" class="button3" name="product" id="product" value="' . $row['product'] . '" onClick="loadXMLDoc2(\'getShow.php\',\'txtHint\',\'theme=\'+encodeURI(document.getElementById(\'rtheme\').value))" > '; } echo '<br /><br /> <div id="txtHint"><div> <br /> <br />'; mysql_close($con); ?> And getShow.php produces a table with a list of product images, names and prices, based on theme. So basically not sure where I am going wrong here? i got javascripts button : Code: <input type="button" value="select" onClick="document.getElementById('input').select()" /> how can i transform "button" to image button (gif) I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery i am trying to make a button which is a .gif that will change when a mouse over occurs and a animation will occur when click then will relocate to a new page but i am getting multiple images at the same time pleas help. Code: <html> <body> <img src="Jepordy/Fla files/Button set 1.gif" > <img name="jsbutton" src="Jepordy/Fla files/Button set 1.gif" width="550" height="400" border="0" alt="javascript button"> <SCRIPT language="JavaScript"> var myimgobj = document.images["jsbutton"]; </SCRIPT> <A href="#" onMouseOver="return changeImage()" ><img name="jsbutton" src="Jepordy/Fla files/Button mouse over.gif" width="550" height="400" border="0" alt="javascript button"></A> <SCRIPT language="JavaScript"> function changeImage() { document.images["jsbutton"].src= "C:\Documents and Settings\fus10n\Desktop\Jepordy\Fla files\Button mouse over.gif"; return true; } </SCRIPT> <A href="#" onMouseOver="return changeImage()" onMouseOutwidth="550" height="400" border="0" alt="javascript button"= "return changeImageBack()" onMouseDown="return handleMDown()" onMouseUp="return handleMUp()" ><img name="jsbutton" src="Jepordy/Fla files/Button set 1.gif" width="550" height="400" border="0" alt="javascript button"></A> <SCRIPT language="JavaScript"> function changeImage() { document.images["jsbutton"].src= "C:\Documents and Settings\fus10n\Desktop\Jepordy\Fla files\Button set 1.gif"; return true; } function changeImageBack() { document.images["jsbutton"].src = "C:\Documents and Settings\fus10n\Desktop\Jepordy\Fla files\Button set 1.gif"; return true; } function handleMDown() { document.images["jsbutton"].src = "C:\Documents and Settings\fus10n\Desktop\Jepordy\Fla files\Button set 1.gif"; return true; } function handleMUp() { changeImage(); return true; } </SCRIPT> <A href="QUESTION LOCATION FOR THIS BUTTON GOES HERE!" onMouseOver="return changeImage()" onMouseOut= "return changeImageBack()" onMouseDown="return handleMDown()" onMouseUp="return handleMUp()"> <A href="http://www.javascript-coder.com/" onMouseOver="return changeImage()" onMouseOut= "return changeImageBack()" onMouseDown="return handleMDown()" onMouseUp="return handleMUp()" ><img name="jsbutton" src="Jepordy/Fla files/Button mouse over.gif" width="550" height="400" border="0" alt="javascript button"></A> </body> </html> can anyone give me a sample code for this situation ? - button A = labeled as Unlocked - when I on mouse over button A the label should turn into "Lock me ?" - and then when I click the button, the label will change to "Locked" Hey all im getting used to using .js still and I am trying to figure out how to create a button to move a selected field within a box of fields to the top, instead of just moving it one-by-one to the top. Here is what I currently have that moves the selected just up one. Can someone expand on this and make it so it will move to the top instead of just one? SearchFieldsWindow.prototype.cmdMoveUp_OnClick = function() { var searchFields = this.__searchFields; var items = this.__lstSelected.get_Items(); var selectedIndices = this.__lstSelected.get_SelectedIndices(); var count = selectedIndices.get_Count(); for (var i = 0; i < count; i++) { var selectedIndex = selectedIndices.get_Item(i); // Don't allow when first item selected if (selectedIndex == 0) break; var uniqueID = items.get_ItemValue(selectedIndex); var label = items.get_ItemLabel(selectedIndex); searchFields.MoveUp(uniqueID); items.RemoveAt(selectedIndex); items.Insert(selectedIndex - 1, uniqueID, label); this.__lstSelected.SetSelected(selectedIndex - 1, true); this.__lstSelected.SetSelected(selectedIndex, false); } }; I have this line of code: <input type='text' id='fCode' style="width:875px; height:22px;"/><br /><br /> Does anyone know how to add a copy button to so when you click it it copies everything in the box to your clipboard? Thanks -Wardman I need to use javascript in a way in which it will keep clicking a button. The source code for that button is below: Code: <script type="text/javascript"> function set_opacity(id, opacity) { element = document.getElementById(id) if (/MSIE/i.test(navigator.userAgent)) { element.style.filter='alpha(opacity='+opacity+')'; } else { element.style.opacity = opacity/100; } } </script> <div class="recruiter_enabled"> <table cellspacing="0" style="width: 100%"> <tr> <td> <p> <script type="text/javascript"> //<![CDATA[ recruiter_clicks = 1 //]]> </script><a href="/recruiter/recruit/3p5tjd4pdnbg0" id="recruit_link" onclick="return(submit_link_as_post_with_opacity(this, 'recruit_image'))"><img alt="" class="start_recruiting" id="recruit_image" src="/A.gif?1221518016" /></a><script type="text/javascript"> //<![CDATA[ link = document.getElementById('recruit_link'); link_href = link.href; link.href = "#"; set_opacity('recruit_image', 50); setTimeout("link = document.getElementById('recruit_link'); link.href = '" + link_href + "'; recruiter_clicks = 0; set_opacity('recruit_image', 100)", 2000); //]]> </script> Therefore, I need javascript to keep clicking the button until it has clicked it 375 times. How would I be able to do this? Hi im new to javascript , i have a game when 2 or more players enter the game a button appears one of the players clicks the button the game starts, what i want to do is when 2 or more players join the game i want the game to start, and not start by using the button. here is the code for the button. PHP Code: if(($hand == '') && ($numplayers > 1)){ ?> var betbuttons = '<'; betbuttons += 'input type="button" name="Button" value="<? echo addslashes($BUTTON_START); ?>" class="betbuttons" onclick="push_action(\'start\');">'; I'm tryingto make a button where, when you click the button, a variable will increase and refresh (reload the number displayed, but one number higher. Here is what I have: Code: <html> <head> </head> <body> <script type="text/javascript"> x=1 document.write(x) </script> <input type="button" value="Up" onclick="document.write (++ x) "> <input type="button" value="Down" onclick="document.write (-- x)"> <input type="button" value="Reload" onclick="history.go(0)"> </body> </html> The problem with this is: When you hit the "up" button, everything on the page dissapears and it just outputs "2". All the buttons and stuff dissapear? There must be a better way to do it. And would I need to use a database. Any help? hello everyone I am working on a quiz which marks the user and displays to different screens when the total has been calculated. If the user gets over 80% a congratulations page is shown but if you score less your told to go back and look at some of the material again. I would like the congratulations page to show a button to let the users continue on to the next section of the tutorial. Does any one have any ideas how I could do this? im stumped. I have inserted the code below, any help would be much appreciated as I'm a little stuck :/ Code: // Function to create arrays. function makeArray(len) { for (var i = 0; i < len; i++) this[i] = null; this.length = len; } // creates objects for this question. function makeQuestion(question, correctAnswer) { var args = makeQuestion.arguments; this.question = question; this.correctAnswer = correctAnswer; this.userAnswer = null; this.isCorrect = isCorrect; this.showForm = showForm; this.userChoices = new makeArray(args.length - 2); for (var i = 0; i < args.length - 2; i++) { this.userChoices[i] = args[i + 2]; } } // determins if the questions answered correctly function isCorrect() { if (this.correctAnswer == this.userAnswer) return true; else return false; } // Method to display contents of question object. function showForm(n) { //argument n is the number of the question. document.write((n + 1) + '. ' + this.question + '<BLOCKQUOTE><FORM>'); //n+1 = the number of the question in the array (has to add one because the array starts with 0 or the first question would be number 0, this question displays the questions text, blockquote off sets the answer making them indented. for (var i = 0; i < this.userChoices.length; i++) { //goes through the questions one by one. document.write('<INPUT TYPE = "RADIO" NAME = "q' + n + //create the radio buttons. '" onClick = "quiz[' + n + '].userAnswer = ' + i + '">'); document.write(this.userChoices[i] + '<BR>'); } document.write('</FORM></BLOCKQUOTE>'); } // This corrects the quiz, dispays the correct answers and the score. function correctQuiz() { var correct = 0; // sets the correct page to a score of zero correctPage = '<HTML><TITLE>Corrections</TITLE><BODY BGCOLOR = "#FFFFFF">'; // sets the attributes of the correction page for (var i = 0; i < quiz.length; i++) { //loop runs through questions if (quiz[i].isCorrect()) correct++; // the is correct starts at 0 every time is correct returns true (an answer is correct) it adds 1 to the number adding up correct answers. } var score = Math.round((correct / quiz.length) * 100); // find out the % of correct answers by using math and the % equation correctPage += 'Sco <STRONG>' + score + '</STRONG> %'; if (correct < (quiz.length / 100) * 80) { //if the correct number is less than the quiz length then not all the answers were correct if it is the same then all ansers were correct. correctPage += ifWrong; // if there were wrong answers for (var i = 0; i < quiz.length; i++) { // starts a for loop through the answers if (!quiz[i].isCorrect()) { // if quiz doesn't = to iscorrect. correctPage += (i + 1) + '. ' + // this shows what number was wrong. quiz[i].userChoices[quiz[i].correctAnswer] + '<BR>'; // displays the correct answes for the questions that were wrong } } } else correctPage += ifAced; // this is the correct page displayed if all the answers were right. correctPage += '</BODY></HTML>'; // opens the window of correct page correctwin = window.open ('', '', 'height=300,width=300,scrollbars=yes'); if (correctwin.opener == null) correctwin.opener = window; correctwin.location = 'javascript:opener.correctPage'; } // Message to display if quiz is aced. var ifAced = "<P>Well done! you have passed the test. You can now move on to the next section of the tutorial<P>"; // Message to display if any are wrong. var ifWrong = "<P>Check below to see the answers that you got wrong. It maybe helpful if you go back and read the bits your unsure of.<P>"; // Create seven question objects... quiz = new makeArray(8); // this is how many questions there is in the quiz quiz[0] = new makeQuestion("What is the correct name for the leg marking found in picture 1?", // 1st question starts at 0 because thats the first number in an array 2, // correct answer "Sock", // choice 0 "Stocking", // choice 1 "Coronet band", // choice 2 "half cannon"); // choice 3 quiz[1] = new makeQuestion("What is the correct name for the leg marking found in picture 2?", // 2nd question 0, // correct answer "Sock", // choice 0 "Stocking", // choice 1 "Coronet band", //choice 2 "half cannon"); //choice 3 quiz[2] = new makeQuestion("What is the correct name for the leg marking found in picture 3?", 1, // correct answer "Sock", // choice 0 "Stocking", // choice 1 "Coronet band", //choice 2 "half cannon"); quiz[3] = new makeQuestion("What is the correct name for the leg marking found in picture 4?", 3, // correct answer "Sock", // choice 0 "Stocking", // choice 1 "Coronet band", //choice 2 "half cannon"); quiz[4] = new makeQuestion("What is the correct name for the face marking found in picture 5?", 2, "Bald", "Star", "Snip", "Blaze"); quiz[5] = new makeQuestion("what is the correct name for the face marking found in picture 6?", 0, "Bald", "Star", "Snip", "Blaze"); quiz[6] = new makeQuestion("what is the correct name for the face marking found in picture 7?", 3, "Bald", "Star", "Snip", "Blaze"); quiz[7] = new makeQuestion("what is the correct name for the face marking found in picture 8?", 1, "Bald", "Star", "Snip", "Blaze"); Hello. I have created a Bold button - when i click the button it applies it into my textarea. The Problem is if i want to apply the bold style only to a single line and the rest of the written text will be normal and not bold it doesn't work. How can I add to the function that when i select a certain line and click on the button to make it bold only the selected line will be bold?? This is the script : PHP Code: <script type="text/javascript"> function bold(id) { var element = document.getElementById(id); element.style.fontWeight = ( element.style.fontWeight == "bold" ) ? "normal" : "bold"; } </script> And this is the button : PHP Code: <img src="Bold.bmp"width="42" height="39" title="Bold Font" onclick="bold('bodytext')" style="cursor:pointer;" /> Dear Seniors I am facing a problem. it entangled me by the last almost three days. actually i am new to programming. i need ur help. what i want to do is that I enter a value in text box and click on submit button. the entered value prompts using alert or prompt function. No further sending of value anywhere. the code is below for HTML and JavaScript. I know i would be making some drastic blunder. plz help me. <form name="mainqryfrm" method="post" action=""> <label></label> <table width="100%" border="0" cellpadding="15"> <tr> <td width="20%"><label><span class="style2">Query Title:</span></label></td> <td colspan="2"><input name="txtqrytitle" type="text" id="txtqryTitle" size="40"></td> </tr> <tr> <tr> <td> </td> <td width="30%"><div align="right"> <input type="submit" name="BtnSubmit" id="button" value="Submit Form" onClick="submitqry(This)"> </div></td> <td width="50%"><input type="reset" name="BtnClrtxt" id="BtnClrtxt" value="Clear Form"></td> </tr> </table> </form> Function submitqry() { var qryfrm; var qrytitle; qryfrm = document.form("mainqryfrm"); qrytitle = document.elements("txtqrytitle").value; document.alert(qrytitle); // return true; } Hi, i have the next code: PHP Code: Code: <span id="review-buttons-container" class="a-center"> <input type="image" src="<?php echo $this->getSkinUrl('images/btn_place_order.gif') ?>" onclick="review.save();" value="<?php echo $this->__('Place Order') ?>" /> </span> </p> </div> <script type="text/javascript"> //<![CDATA[ var review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder') ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements')); //]]> </script> and i add the follow JavaScript code to create checkbox (the idea is that only when you with the checkbox checked, the button work) i try: PHP Code: Code: <span id="review-buttons-container" class="a-center"> <form action="" onSubmit="return check(this);"> <input name="chkbox" value="please make sure i'm checked" type="checkbox" /> <input type="image" src="<?php echo $this->getSkinUrl('images/btn_place_order.gif') ?>" onclick="review.save();" value="<?php echo $this->__('Place Order') ?>" /> </form> </span> </p> </div> <script type="text/javascript"> //<![CDATA[ function check(form){ if( form.chkbox.checked ) return true; else{ alert("please check the checkbox"); return false; } } var review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder') ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements')); //]]> </script> but its not work for me my javascript knowledge is not so good, please help me to create this checkbox) Thanks. Hi, I was trying to add some simple javascript (toggle visibility function of a div) to the FB 'like' button and 'Google +1' button. This to simply create some more visitor interactivity by showing a thank you message for doing so. I've tried by just adding 'onclick=' to the element that actually shows the button, with a <a href="#" onlcick="..."> --element--</a> manner, and with a <span> and a <div> element around it. Neither of them work. The toggle script is 100% correct (using it actively with <a href="javascript:void(0);" onclick="javascript:toggleVisibility('feedbackform')">feedback</a> ) Of course I made sure the div id had correct name and it is unique for the toggle function. Anybody got any ideas on how to go with this? JS: Code: function toggleVisibility(controlId) { if (document.getElementById) { // DOM3 = IE5, NS6 var control = document.getElementById(controlId); if(control.style.display == "") control.style.display = "none"; else control.style.display = ""; } else { if (document.layers) { // Netscape 4 if(document.controlId.display == "") document.controlId.display = "none"; else document.controlId.display = ""; } else { // IE 4 if(document.all.controlId.style.display == "") document.all.controlId.style.display = "none"; else document.all.controlId.style.display = ""; } } } |