JavaScript - Onchange Event - Textbox To Enable Radio Buttons
Hi,
I have a form consisting of nine text fields (labelled 1-9) and nine radio buttons for each of the text fields. I want to enable the radio buttons when text is entered into the field corresponding to that particular radio button. Is there a way of achieving this using a JavaScript onChange event? Thank you in advance. Similar TutorialsHello, On a simple form, there is a radio button group with two radio buttons, a text box, and a submit button. The first radio button is checked(selected) by default. The text box input has the onChange event handler so that if the text is changed, the second radio button will be checked(selected). The problem is the input radio name contains a hyphen that breaks the JavaScript and the name can not be changed. What is the correct syntax for referencing a hyphenated form input radio name in the onChange event? Here is the form that works correctly with no hyphen in the input radio name: Code: <form name="myFormGood" action="" onsubmit="return false;"> Good Form with no hyphen in radio button name<br> <input name="radio1" type="radio" value="4" checked> First Option<br> <input name="radio1" type="radio" value="5"> Second Option<br><br> Change the text to select the Second Option<br> <input type="text" name="text1" onChange="document.myFormGood.radio1[1].checked = 'true';" size="10" value=" "><br><br> <input type="button" name="submit" value="It Works!"> </form> Here is the form that breaks the JavaScript because it has a hyphen in the input radio name: Code: <form name="myFormBad" action="" onsubmit="return false;"> Bad Form with hyphen in radio button name breaks JavaScript<br> <input name="radio-1" type="radio" value="4" checked> First Option<br> <input name="radio-1" type="radio" value="5"> Second Option<br><br> Change the text to select the Second Option. Nothing Happens.<br> <input type="text" name="text1" onChange="document.myFormBad.radio-1[1].checked = 'true';" size="10" value=" "><br><br> <input type="button" name="submit" value="It Doesn't Work!"> </form> Hi there. I came across this forum while searching for an example of how to do something in Javascript, and found the post helpful, but didn't quite answer my query completely... It was a very old thread, few years old, though so I thought best not to revive it from the murky depths Basically, I very rarely use JavaScript... in fact, I rarely do any programming at all, but I'm trying to build a basic site at the moment, and I'm wanting to disable/enable a text box based on the value of a drop down menu... The idea behind it is that I have a sub title, and in the admin panel, I want to be able to set whether the sub title is picked randomly from a database, or whether it chooses one, and only one... So in the admin panel, I've got a page that has a drop down menu with two options. Static, and Random. Below this, I've got a text box called Static ID... In this text box, the administrator would insert the database row ID for the specific sub title they want... Obviously this Static ID field only applies if you select a Static sub title, rather than a Random sub title... So what I want to happen is for the text box to be disabled if the drop down menu is selected as Random... and then enabled if the drop down is selected as Static... So I came across the following script on an old post as mentioned earlier: Code: <script type = "text/javascript"> function enableTextbox() { if (document.getElementById("dropdown").value == "New") { document.getElementById("txt1").disabled = false; } else { document.getElementById("txt1").disabled = true; } } </script> <form action="adm_subtitle.php" method="post"> Static or Random? <select name="staticrand" id"staticrand" onchange="enableTextbox()"> <option value="static">Static</option> <option value="rand selected="selected">Random</option> </select> Static ID <input type="text" value="0" name="staticid" id="staticid" maxlength="3" disabled="true" /> <input type="submit" name="submitsubtitleset" value="Submit" /> </form> With a bit of other formatting that isn't necessary for this example... Now, this works if I change the drop down box to Static, it'll enable the text box, and then disable the text box if I select Random... The problem I've got though, is with a bit of PHP code mixed in with the form, it will check the current value of the setting, and then choose which drop down menu to pick as selected... so if in the backend config it's set to "rand", it'll automatically pick Random when the page loads, and if it's set to "static", it'll automatically pick Static when it loads the page... If it's already set to Static, the page loads and the text box is disabled. I have to select Random from the drop down list, and then select Static again to enable the box... Is there anyway that I can enable it if Static is already selected when the page loads and then disable it when Random is selected, but still keep the functionality that it is already disabled when the Random option is selected on load? I hope that makes sense... Cheers, Mike. Hi I'm a newbie. Please help me. I'm using Joomla. I've got a dropdown which reads the filename from the database. When the user selects it I want an onchange event to open the pdf. I've been at it for 2 days now. Code: <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("metnet", $con); $sql="SELECT * FROM newsletter"; $result = mysql_query($sql); echo "<form method='post'>"; $dropdown = "<select name='sname' onChange='location(this.form.sname)' >"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['fpath']}'>{$row['fpath']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> Hi, I am trying to copy the value of one textbox to another using onchange event. For some reason, my code does not work, please let me know where I went wrong. here is my code: Code: <html> <head> <script type="text/javascript"> function copyText() { document.getElementById("field2").value=document.getElementById("field1").value; } </script> </head> <body> Field1: <input type="text" id="field1"/><br /> Field2: <input type="text" id="field2" onchange="copyText()"/> </body> </html> Thank you. HI, i know very little about javascript, just enough to get me into trouble actually lol. Here is what im working with. I have a custom Instant messenger for members. It uses embed object macromedia as well as javascript to diplay the window and send messages. What i want to do is simply add an onchange that when one person is typing it shows they are typing (ie xxxxx is typing....) My experience is in php and html and i looked thru the script and the javascript functions but im not sure what im looking for exactly. Do i need to have access to the swf or fla file and be able to edit them to do this? I dont see any form inputs or i would know exactly where to put the onchange lol. Im guessing the input is in the swf or fla file not sure how that works. what im guessing is that in the embed or the object tags (ill play with it) i can put something like Code: document.write('test on change\n'); i think i need to wrap that in doc write script type=javascript in quotes so it parses. If i can get that text to show up inside the IM where i want it then i can try to figure out how to set focus on box and recongize onchange and do some testing. I think i might even be able to doc write the onchange command but not sure. Thanks Within my project, using PHP/HTML/Javascript, I am trying to set up a page where a corresponding submit button is enabled when a given checkbox is checked. What complicates my attempt is that the checkboxes and submit buttons are in the form of arrays. Here is a snippet of my code: Code: <form name="myform4" id="list_apps" method="post"> <?php for ($i=0; $i<$num_rows;$i++) { ?> <p> <input type="checkbox" name="app[]" id="app[]" onclick="enable_perm()"> <input name="set_perm[]" type="submit" id="set_perm[]" value="Set Permissions"> </p> <?php } </form> Here is my attempt at using Javascript to disable the first submit button after clicking any check box: Code: function enable_perm() { document.myform4.set_perm[0].disabled = true; } What am I missing here, or, how do I enable/disable submit buttons that are part of an array? This is my table which the user will see. When the user select a category, the table will show the result. Therefore the number of row of details that will be shown is uncertain. Over here i show 3 example. ------------------------- Edit | Name | Number | ------------------------- radbtn | John | 123456 | radbtn | MJ | 654321 | radbtn | JP | 443224 | I have a edit button. Once i click on it all my N amount of radio button will be enable. How can i do it? the problem is i have to hard code it [0] [1] [2], how can i change it to N? document.formname.btnname[0].disabled=false; thanks for helping anyone! I'm having trouble programming a radio button to enable a group of checkbox options. I want the group to be disabled unless the radio is selected. Can I use: Code: document.getElementById("").disabled=true/false for a <div> section? Here's what I have so far. function: Code: function disableSection() { if (document.forms.radio.checked) document.getElementById("optionalinfo").disabled = false; else document.getELementById("optionalinfo").disabled = true; } HTML: Code: <input type="radio" name="additionalinfo" value="yes"/>Yes! Please sign me up for the following items:<br/> <div><blockquote><input id="optionalinfo" type="checkbox" name="additional" value="newsletter"/> I wish to receive <font color="ff69b4"><i>AMT</i></font>'s monthly E-Zine, <b>"Glorious Morning Muffins"</b>.</br> <input id="optionalinfo" type="checkbox" name="additional" value="Updates"/> I wish to receive <font color="ff69b4"><i>AMT</i></font> updates.</br> <input id="optionalinfo" type="checkbox" name="additional" value="future"/> Keep me posted about future offerings at <font color="ff69b4"><i>AMT</i></font>.<br/> <input id="optionalinfo" type="checkbox" name="additional" value="userRegister"/>I need to register to log in</blockquote></div> In addition to this, I would like the section to fade when disabled. Thanks for any help... again! Hello ladies and gentlemen, I would like to use some event handling on a form, not something I have done before and looking for some assistance. Here is my code: Code: <select name="LocO"> <option value=""></option> <option value="O">Outside</option> <option value="I">Inside</option> </select> <select name="LocA"> <option value=""></option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> <option value="D">D</option> <option value="E">E</option> <option value="F">F</option> <option value="G">G</option> <option value="H">H</option> <option value="I">I</option> <option value="J">J</option> <option value="K">K</option> </select> <select name="Loc1"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> So what I need to happen, is based on the selection of the first selection box, some of the options of the other selection boxes should not be available. If Outside is selected, everything in LocA should be available, but only up to 4 in Loc1... and if Inside is selected, only up to E should be available in LocA and everything should be available in Loc1. Is this possible? Hi All, Need a bit of help here, need this SELECT to submit the page and end up at the below URL, correctly passing the GET values through the string. <code> <select name="dir-fact-misma" id="dir-fact-misma" class="text100" tabindex="" onChange="alta_nueva.action='alta.php?page=p2#alta'; return true;"> <option value="Si" <?php if(!isset($_POST['dir-fact-misma']) || $_POST['dir-fact-misma'] == 'Si') print "Selected='Selected '"; ?>>Si</option> <option value="No" <?php if(isset($_POST['dir-fact-misma']) && $_POST['dir-fact-misma'] == 'No') print "Selected='Selected '"; ?>>No</option> </select> </code> the form in which this SELECT is placed needs to be submitted so that other fields in the form are not lost, they are saved in Session Variables. the same javascript but activated through an onclick event works perfect elsewhere in the same form with the following code, i think its the onChange that doesn't work for some reason. <code> <input name="p1" type='submit' id="p1" onclick="alta_nueva.action='alta.php?page=p1#alta'; return true;" value='1' /> </code> the page is programmed in PHP. Any help is appreciated. I am trying to add an onchange event to a select tag. This is my code, but it does not appear to be working. Any advice is appreciated. Thanks... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> <script type="text/javascript"> function myLoad () { var mySelect = document.getElementsByName('test'); mySelect.onchange = function(){alert('hi')}; } </script> </head> <body onLoad="myLoad()"> <select name="test" > <option value="1">1</option> <option value="2">2</option> </select> </body> </html> Hi All, I am really strugling with this and I hope somebody can help me on this. I would like to have a dropdown to only show when a certain value is chosen from another drop down. So if in this dropdown the value ETS Rep Discount is chosen he should show the other dropdown Code: <div class="row"> <div class="fieldName">Discount Type</div> <div class="fieldValue"> <asp:DropDownList ID="discountTypeDropDownList" runat="server" AutoPostBack="True" Width="295px" OnSelectedIndexChanged="DiscountTypeDropDownList_SelectedIndexChanged"> <asp:ListItem Value="<%$ AppSettings:DiscountType.General %>">General Discount</asp:ListItem> <asp:ListItem Value="<%$ AppSettings:DiscountType.Golf %>">Golf Only Rep Discount</asp:ListItem> <asp:ListItem Value="<%$ AppSettings:DiscountType.ETS %>">ETS Rep Discount</asp:ListItem> </asp:DropDownList> </div> </div> Code: <div class="row"> <div class="fieldName">Category</div> <div class="fieldValue"> <asp:UpdatePanel ID="UpdatePanelCategory" runat="server"> <ContentTemplate> <asp:DropDownList ID="CategoryDropDown" runat="server" Width="295px"> </asp:DropDownList> <asp:Label ID="CategoryRequiredLabel" runat="server" Font-Bold="True" ForeColor="Red" Visible="False">required!</asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="discountTypeDropDownList" /> </Triggers> </asp:UpdatePanel> </div> </div> thanks in advance All, first post on the forum. I hope this is relatively simple. I've looked around for the answer, but I thin think the search terms (update onchange event) are a bit too common... Code: document.getElementById("tester").innerHTML= "hello"; document.getElementById("tester").onmouseover = "alert('hello')"; You see I'm trying to change an event like I'd change a property. The first will change the text to hello. I'd like the second to change the onmouseover event to display a hello world alert... but it doesn't seem to do anything. How can I change events? Jason Hi all, I want to reload an html page onChange event of dropdown list and retain the old values filled in the page. Plz help..... Hello, I have this onchange event that occurs after user selection of a dropdown menu. When a user makes a selection it queries the database and delivers some data. The value of the dropdown is stored in a database, but the problem is when the page is refreshed the delivered data disapears, only reappearing if you change the dropdown. How can I make the onchange event run when the page loads so that if there is already a selection, the database data will always be there, only to change if the user changes the selection? Here is the JS: Code: <script type="text/javascript"> function showCustomer(str) {var xmlhttp; if (str=="") {document.getElementById("txtHint").innerHTML=""; return;} if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest();} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");} xmlhttp.onreadystatechange=function() {if (xmlhttp.readyState==4 && xmlhttp.status==200) {document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}} xmlhttp.open("GET","getcustomer.asp?q="+str,true); xmlhttp.send();} </script> And the onchange line: Code: <SELECT Name=""customers"" id=""customers"" onchange=""showCustomer(this.value)""> Etc... Please ignore the double sets of quotes. Hello, I am working on a CGI/Ajax application to interface with a database. I have the back-end Perl/CGI application working, so now it it is time to design the web interface and respective forms. So here goes, I am attempting to create dynamic list boxes, but I am unable to pass a value to the 'onChange' event. Here is my code (this is a proof of concept and highly stripped down): Code: <html> <head> </head> <body> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> var array = [ 'name', 'age', 'year']; function init(sel_val){ for (var i = 0; i < array.length; i++){ document.write(i + " " + array[i] + "<br />"); } for (var i = 0; i< array.length; i++){ document.product.id_type.options[i] = new Option(i + array[i], i); } } function OnChange(sel_val) { // for(i = document.product.id_style.length - 1; i > 0; i--) // document.product.id_style.options[i] = null; // document.product.id_style.options[0] = new Option("something else", 15); alert("pressed" + " " + sel_val + "<br />"); } </script> <form name="product"> <select name="id_type" size="5" style="width: 150px;" onChange="OnChange()"></select> <select name="id_style" size="5" style="width: 150px;" ></select> </form> <script> init(); </script> </body> </html> I'm well versed in Perl and Java but I am a JavaScript newbie, so go easy. I understand that sel_val is not being set, but I'm not sure how it should (or could) be set. I would like to use a hash instead of integer values for `i` document.product.id_type.options[i] = new Option(i + array[i], i); becomes document.product.id_type.options[i] = new Option(hash[key], key); Any thoughts, comments, criticisms, jokes are welcome. Thanks in advance for the assist. Hi All, I have a script that is called by the onchange event on my text field (it compares the date entered into the field and issues an alert if the date is earlier than the current date). This worked great on my data entry form but I also want to use the same script in my update form. In the update form the text field is already receiving a value via php: Code: <input name="DateNeeded" type="text" class="formField" id="DateNeeded" onchange="checkDate(this)" value="<?php echo $row_rstRequestDetails['DateNeeded']; ?>" /> and this is causing my onchange event to fire when the page is loaded. Is there a way to suppress the onchange event for the initial page load? Thanks, Ken Hello, I'm working on a quote generator and I'm running into an issue with onChange events not firing when a text field is dynamically populated via a child window. Here's my setup: I have 3 text boxes (quantity, price, markup) that are multiplied together in order to give the total of that product. Each text box has an onChange event [called calculator()] that calls an external javascript file, which handles the multiplication and instantly updates the total of that product. Up to this point, everything works fine - - when I manually edit any of the 3 inputs, the total updates correctly. However, my problem is that I now have the "price" text box being dynamically populated, and when it updates it is not firing the onChange event attached to it. The text box is being filled by way of launching a child window and running the following code within it: Code: function call_submit() { opener.document.quote_form.item_price_1.value=document.child.prods.options[document.child.prods.selectedIndex].id self.close(); } I've also tried to call the calculator function from within the child window, with no luck: Code: function call_submit() { opener.document.estimator_form.item_price_1.value=document.child.prods.options[document.child.prods.selectedIndex].id calculator () self.close(); } So, as of right now, the following is happening - - I launch the child window, I select the product to add to the quote, the child window closes and the price is correctly populates within the "price" text box, BUT the total stays at zero. If I manually edit any of the fields, it then catches back up and properly updates the total. Is their any way to fire the onChange event at the time when the text field is populated from the child window? Any help would be appreciated. Thanks in advance. Hello All I was hoping you guys can help. I have 3 radio fields which when clicked on I want it to change the background colour of the table its within. The radio fields have the same name so only one can be selected at once. At the moment its changing the background yellow but if I click another radio field its not resetting back to normal (white). Im not sure how to achieve this is javascript... Here is the code im using now: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript" language="javascript"> function swapColor(oCheckbox) { var pop = oCheckbox, checkedcolor = 'yellow'; while (pop.nodeType != 1 || pop.nodeName.toLowerCase() != 'table') pop = pop.parentNode; if (typeof pop.oldcolor == 'undefined') pop.oldcolor = pop.style.backgroundColor; pop.style.backgroundColor = (oCheckbox.checked) ? checkedcolor : pop.oldcolor; } </script> </head> <body> <table> <tr> <td> <input type="radio" name="change" value="0" onchange="swapColor(this) checked" />11111111 </td> </tr> </table> <table> <tr> <td> <input type="radio" name="change" value="1" onchange="swapColor(this)" />22222222 </td> </tr> </table> <table> <tr> <td> <input type="radio" name="change" value="2" onchange="swapColor(this)" />33333333 </td> </tr> </table> </body> </html> I would appreciate any help! Thanks! |