JavaScript - Onchange Change Display Question
Hi, I am effectively using this script to grab elements based on a select from the db: http://www.w3schools.com/PHP/php_ajax_database.asp
My question is, how can I, instead of changing what's present on the page, change the display value to "none", so the elements that are being gathered can be re-submitted to the form? Thanks Code: <script type="text/javascript"> function showUser(str) { 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","getuser.php?q="+str,true); xmlhttp.send(); } </script> Similar TutorialsGood day, I'm populating a combo box and I'm working to onchange the url of a div.based on the value selected. Here is my code : PHP Code: <?PHP $console = $_GET['console']; $dir = "Names/"; echo "<select name=\"console\" onchange=\"load('console_info.php?console=<SCRIPT language=\"javascript\">document.write(this.options[this.selectedIndex].value)</script>','page')\" onmouseclick=\"this.focus()\">"; // Open a known directory, and proceed to read its contents $dir_handle = @opendir($dir) or die("Unable to open $dir"); $files = array(); while($file = readdir($dir_handle)) { if($file != '.' and $file != '..') { $files[] = $file; } } sort($files); foreach($files as $file) { if($file != $console) { echo "<option value='$dir/$file'>$file</option>\n"; }else{ echo "<option value=\"$dir/$file\" selected=\"selected\">$file</option>\n"; } } echo "</select>"; ?> I already have a script which make me able to change the url of a div with ajax, this works well. Here is the code which do that: PHP Code: <script type="text/javascript"> function ahah(url, target) { document.getElementById(target).innerHTML = ' Fetching data...'; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if (req != undefined) { req.onreadystatechange = function() {ahahDone(url, target);}; req.open("GET", url, true); req.send(""); } } function ahahDone(url, target) { if (req.readyState == 4) { // only if req is "loaded" if (req.status == 200) { // only if "OK" document.getElementById(target).innerHTML = req.responseText; } else { document.getElementById(target).innerHTML=" Error:\n"+ req.status + "\n" +req.statusText; } } } function load(name, div) { ahah(name,div); return false; } </script> onchange="load('console_info.php?console?=','page')" The part I have problem with is the part when the combo box get changed with an onchange, I don't know how to add after the console?= as the user change the option . example: PHP Code: <SCRIPT language="javascript\">document.write(this.options[this.selectedIndex].value)</script> But if I do this, since i'm using php to write this it only write that. I don't know how can i make this work. Thanks! I'm using onchange display to hide/show form elements depending on the value of a select box. It works perfectly well (I actually really adore it) for one select box, but I have another select box which I'd like to act similarly. Code: <head> <script type="text/javascript"> // <![CDATA[ function display(obj,id1,id2,id3,id4) { txt = obj.options[obj.selectedIndex].value; document.getElementById(id1).style.display = 'none'; document.getElementById(id2).style.display = 'none'; document.getElementById(id3).style.display = 'none'; document.getElementById(id4).style.display = 'none'; if ( txt.match(id1) ) { document.getElementById(id1).style.display = 'block'; } if ( txt.match(id2) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id3) ) { document.getElementById(id3).style.display = 'block'; } if ( txt.match(id4) ) { document.getElementById(id4).style.display = 'block'; } } // ]]> </script> </head><body> <form action="#"> <select name="Stype" onchange="display(this,'oneshot','outtake','multi','chapter');"> <option>Please select:</option> <option value="oneshot">Oneshot</option> <option value="outtake">Outtake</option> <option value="multi">Original Multi-Chapter</option> <option value="drabbles">Drabbles</option> <option value="outline">Outline Preview</option> <option value="chapter">Chapter Preview</option> </select><BR><BR> <div id="oneshot" style="display: none;">Some fields here</div> <div id="outtake" style="display: none;">Some different fields here</div> <div id="multi" style="display: none;">Some other fields here</div> <div id="chapter" style="display: none;">Some more fields here</div> </form> </body> But when I go to add a second select (obj,id1,id2,id3,id4,id5,id6) with new "ifs" and id's, etc and so forth, neither work. Code: <head> <script type="text/javascript"> // <![CDATA[ function display(obj,id1,id2,id3,id4,id5,id6) { txt = obj.options[obj.selectedIndex].value; document.getElementById(id1).style.display = 'none'; document.getElementById(id2).style.display = 'none'; document.getElementById(id3).style.display = 'none'; document.getElementById(id4).style.display = 'none'; document.getElementById(id5).style.display = 'none'; document.getElementById(id6).style.display = 'none'; if ( txt.match(id1) ) { document.getElementById(id1).style.display = 'block'; } if ( txt.match(id2) ) { document.getElementById(id2).style.display = 'block'; } if ( txt.match(id3) ) { document.getElementById(id3).style.display = 'block'; } if ( txt.match(id4) ) { document.getElementById(id4).style.display = 'block'; } if ( txt.match(id5) ) { document.getElementById(id5).style.display = 'block'; } if ( txt.match(id6) ) { document.getElementById(id6).style.display = 'block'; } } // ]]> </script> </head><body> <form action="#"> <select name="Stype" onchange="display(this,'oneshot','outtake','multi','chapter');"> <option>Please select:</option> <option value="oneshot">Oneshot</option> <option value="outtake">Outtake</option> <option value="multi">Original Multi-Chapter</option> <option value="drabbles">Drabbles</option> <option value="outline">Outline Preview</option> <option value="chapter">Chapter Preview</option> </select><BR><BR> <div id="oneshot" style="display: none;">Some fields here</div> <div id="outtake" style="display: none;">Some different fields here</div> <div id="multi" style="display: none;">Some other fields here</div> <div id="chapter" style="display: none;">Some more fields here</div> <BR><BR><BR> <select name="Atype" onchange="display(this,'romance','adventure');"> <option>Please select:</option> <option value="romance">Romance</option> <option value="adventure">Adventure</option> </select><BR><BR> <div id="romance" style="display: none;">Some new fields here</div> <div id="adventure" style="display: none;">Some even newer fields here</div> </form> </body> Is there any way to fuse them and get a second select to work the same? Thanks in advance for the help! Hi I'm trying to get button to change word + triangle. This ▼ or ▲ is Hex for triangle. I hard code this <input name="b" value="More▼" page loads, the value shown on button is "More and a triangle" (as I would like) but when I then do document.getElementById("moreBtn").value="Less▲" the button displays "Less▲"; (ie no triangle) why? Is this possible? very grateful If any body can explain. Low Tech this is really starting to irritate me, and I can't figure it out. Here is the Javascript: Code: function shipUPS(str){ var divShip=document.getElementById("deliv2"); if(str=="ups"){ if (divShip.style.display=="none") { divShip.style.display = '';} } else { if (divShip.style.display!="none") { divShip.style.display = "none";} } } CSS: Code: #deliv2 { display: none; } and the HTML: Code: <div id="deliv1">Deliver To: <select name="DelivToCust" tabindex="10" onchange="shipUPS(this.value)"> <option value="cust">Customer</option> <option value="sr">Sales Rep</option> <option value="pick">Pick-Up</option> <option value="ups">Ship UPS</option> <option value="Other">Other</option> </select> </div> <div id="deliv2">Bill for Shipping? </div> as written, it doesn't work. If I change the CSS to: Code: #deliv2 { display: ; } It works beautifully! however I want the DIV hidden from the start. could someone please help me figure this out? Thank you! I am new to JavaScript and I am having a difficult time finding what I thought would be easy to find (so please forgive me if this has been posted somewhere else...) I have 4 text strings that when a user runs his/her mouseOver, I'd like to display a corresponding picture in a display area. I thought that would be easy enough. However, it gets a bit complicated for me since I am also using CSS to position the display area. For some reason all I can find out there are examples using HTML tables for display image positioning. I don't want to use tables. I'm not sure if this will make a difference but my style sheet is external. Also, the text does not link/go to another page. I REALLY hope that made sense. Someone please help me! Hi guys, I've been breaking my brains for few hours, I already searched online and I found nothing so far. What I wanna do.... I have 5 different images linked to 5 different websites. Once the image is clicked, the first link will be displayed in an iframe, and the image will change to the second one. Once we click on the second image, the second link will be displayed using the same iframe, and so on. The code changes the images,but I dunno how to deal with the link to the websites. This is the code: Code: <html> <head> <title>Testing...</title> </head> <script type="text/javascript"> imgs=Array("1.png","2.png","3.png","4.png","5.png"); links=Array("www.vbct.ca","www.cnn.com","www.castanet.net","www.yahoo.com","www.cubaweb.cu"); var x=0; function change() { document.getElementById("changes").src=imgs[++x]; if (x==4) { x=-1; } } if (!imgs[x+1]) { x=-1; } </script> <body> <div> <iframe src="http://www.vbct.ca" style="border: 0; position:relative; top:0; left:0; right:0; bottom:0; width:100%; height:400px;" name="page" width="100%"></iframe> </div> <br /><br /> <div> <a href="#" target="page"><img src="1.png" id="changes" alt="alttext" onmousedown="change()" style="cursor: pointer;" /></a> </div> </body> </html> And this is the link to the test page: http://www.virtualbc.ca/sites/test/ I have the concept down to change the CSS for a label when I click it. <label class="text" onClick="this.className='big_text" style="margin:5px;">Text</label> I was wondering, the goal is that it works, it changes from small text to big text when selected, but how can I change to back to small text from big text and vice versa using java for only the CSS? Much appreciated! C8 www.e-decals.com/dev displays fine in Firefox and Safari, (link color a { color : #b2b2b2 correct) but IE showing default link colors around images in multibox - IE error he User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618) Timestamp: Thu, 5 Nov 2009 15:11:40 UTC Message: Object doesn't support this property or method Line: 467 Char: 4 Code: 0 URI: http://www.e-decals.com/dev/multibox/multibox.js Any ideas? Easier to show than to explain: Code: <head> <SCRIPT LANGUAGE="JavaScript"> function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } </script> </head> <body> <form name="myform"> <table> <tr id="CA" name="list" value="1" style="background-color:yellow;"> <td> <input type="checkbox" name="list" value="1" onclick="document.getElementById('CA').style.backgroundColor=this.checked?'white':'cyan';">Choice CA</td> </tr> <tr id="CB" name="list" value="1" style="background-color:yellow;"> <td> <input type="checkbox" name="list" value="1" onclick="document.getElementById('CB').style.backgroundColor=this.checked?'white':'cyan';">Choice CB</td> </tr> <tr id="CC" name="list" value="1" style="background-color:yellow;"> <td> <input type="checkbox" name="list" value="1" onclick="document.getElementById('CC').style.backgroundColor=this.checked?'white':'cyan';">Choice CB</td> </tr> </table> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> </form> <p>All never touched should be yellow. All checked should have white background. All unchecked should have cyan background.</p> <p>How do I get 'Check All' and 'Uncheck All' to obey the tr background color, too?</p> Hi, I have a body onload doing multiple things, changing a select option value, changing the form submit action and then auto submitting. Everything works fine until the auto submit part of it. Code: function run() { document.myform.myselect.selectedIndex = 1; document.myform.action = 'page.php?x=1&y=2'; document.myform.submit(); } <body onload="run()"> Thanks for any help with this I need to change the source of an image but I can't seem to figure out how. I believe that I have the correct syntax, but it does not seem to be working. Maybe I am typing it in wrong or something. I try to test my javascript by typing the script: <strong>javascript:document.getElementById('img1').src='./images/image1.jpg';</strong> into the address bar. Nothing happens. I also try to test it out by putting this on the page, but once again, nothing happens. Code: <script type="text/javascript"><!-- document.getElementById('im1').src="./scripts/'.$upload_image.'"; //--></script> This is what my HTML code looks like: Code: <img src="./images/temp_wizard_picture.gif" alt="" style="padding:4px; background:#fff; border:1px #bbb solid;" id="img1" /> Can somebody please fill me in on what I am doing wrong. Thank you. Hi, what would be the best way to have a hidden array of possible text directed at a textarea and then if something is not within that array "onfocus", a certain select option is chosen within that form? Thanks Code: <input type = "text" style ='display:none;' onchange="display_data_from_server(this.value)"/> Value inside that input is cahanged from js. Is there any reason that onchange would not happen ? i mean, it does not. I have a onChange value
Code: var people = [ ["Timothy Conner", "1999-Present", "Age: 12", "Male", ""], ["Andrew Conner", "1992-Present", "Age: 19", "Male", ""] ]; var how = "Brothers"; function find() { if(document.getElementById("name").value == people [0] [0]) { document.getElementById("desc").value = people [0] [1] + " " + people [0] [2] + " " + people [0] [3]; } if(document.getElementById("name").value == people [1] [0]) { document.getElementById("desc").value = people [1] [1] + " " + people [1] [2] + " " + people [1] [3]; } document.getElementById("relateb").value = document.getElementById("name").value; } Code: Name: <input type="text" id="name" value="" onChange="find()"/> So for it to proses a name you must click out of a box is ther a way to make it instead of when you click out of it, it would immidiatly change? Hi folks. I'm working on a calculator and need to use the 'onchange' function. Basically, the user selects the year (id=taxYear) and once the year is select (default is 2008) this year will appear in 2 different lines of the page under 2 seperate ID's(ageYear & totalYear). I've looked at a few example of the function but I'm still not sure how to approach it. At the moment the year changes once I hit the 'calculate' button but the onChange would obviously offer a better alternative with the date changing once 'taxYear' is changed. here is the script; Code: //check the year var taxYear = document.getElementById('taxYear').options[document.getElementById('taxYear').selectedIndex].value; document.getElementById('ageYear').innerHTML = taxYear; document.getElementById('totalYear').innerHTML = taxYear; Here is the jsp; Code: <tr> <td align="left" width="203" colspan=""><p> Your Tax Year: </p></td> <td align="left" > <s:select name="taxYear" id="taxYear" list="#{'2008':'2008', '2009':'2009'}" theme="simple" />* </td> </tr> <tr> <td align="left" width="203"><p> Age at December 31st <span id="ageYear"></span></p></td> <td align="left" colspan="1"> <s:textfield name="age" id="age" theme="simple" cssClass="text" value="30" /> * <div id="errorage" class="warningmessage" style="display:none"> Please enter your Age to proceed. </div> </td> </tr> <tr> <td colspan="2" class="basicboldtext"> <br/> The total pension contribution you can make for year <span id="totalYear"></span> is €<span id="totalTax2"></span> <br/> </td> </tr> Appreciate any help on this! This code works great for splitting value to textbox.. However; It quits working in example 2 when I move the select outside the form tags Code: <!-- EXAMPLE 1 WORKS--> <script type="text/javascript"> function Split(sel,first) { if (sel.selectedIndex == 0 ) return; var temp = sel.value.split(","); sel.form["F"+first].value = temp[0]; sel.form["F"+(first+1)].value = temp[1]; sel.form["F"+(first+2)].value = temp[2]; } </script> <form method='post'> <input type="text" name="F1" value="" > <input type="text" name="F2" value="" > <input type="text" name="F3" value="" > <select onChange="Split(this,1)"> <option> ===Select Color ==== </option> <option value='000,000,000'>black</option> <option value='169,169,169'>grey</option> <option value='000,000,255'>blue</option> <option value='153 102,255'>aqua</option> </select> </form> Help with the onChange to work outside the form tags. Code: <!-- EXAMPLE 2 NEED HELP--> <script type="text/javascript"> function Split(sel,first) { if (sel.selectedIndex == 0 ) return; var temp = sel.value.split(","); sel.form1["F"+first].value = temp[0]; sel.form1["F"+(first+1)].value = temp[1]; sel.form1["F"+(first+2)].value = temp[2]; } </script> <form method='post' name="form1"> <input type="text" name="F1" value="" > <input type="text" name="F2" value="" > <input type="text" name="F3" value="" > </form> <!-- NEED TO MODIFY THE ONCHANGE TO WORK IN THIS POSITON?? --> <select onChange="Split(this.form1.value,1)"> <option> ===Select Color ==== </option> <option value='000,000,000'>black</option> <option value='169,169,169'>grey</option> <option value='000,000,255'>blue</option> <option value='153 102,255'>aqua</option> </select> 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 Evening all. I have a little bit of code, thus: Code: var data = document.createElement("td"); box = document.createElement("input"); box.id = headercategories[i]; box.type = text; box.value = "Ten"; box.onChange = alter("11"); data.appendChild(box); in which I insert a text input box into a table data element. When the value of the input is changed, I would like to call the function alter(). However, what's happening in practice is that the function alter is getting called straight away, without waiting for any changes. Is there any way I can stop this? It doesn't seem to happen if you actually write the onchange bit into the HTML by hand rather than doing it dynamically. Thanks, Chris |