JavaScript - Using Innerhtml To Change <input> Values?
I have a script where I need to change input values automatically, and I just can't find the right code for it. Here's a little of my code below, can anyone help me, please?
Code: document.getElementById("Id").innerHTML="Text here"; Similar TutorialsHi all, Hope you can help with the following. I'm trying to change the contents of DIV2 when I click on DIV1. The following code doesn't work for some reason. I'm using Windows 7 (64-bit), and testing on Firefox 3.6.8 and IE8. Code: <html> <head> <script type="text/javascript" language="javascript"> function test() { document.getElementById("test2").innerHMTL="hello"; } </script> </head> <body> <div id="test1" style="border: 1px solid #ff0000; width: 200px; height: 100px;" onclick="test();">Test Box 1</div> <div id="test2" style="border: 1px solid #ff0000; width: 200px; height: 100px;">Test Box 2</div> </body> </html> Any help appreciated, Cheers Sean Hi guys, The code in question is www.spectral.og.uk/test5/work2.htm I am trying to change the main 'SPECTRAL' video content mid-right when I click on the 'Change Movie' at the bottom. Eventually I want to be able to do this from the thumbnails but Im just running a simple test first. So I defined the function 'ChangeMOVIE' on line 14 using document.getElementById & innerHTML, etc, to replicate the flash player script contents that are incidentally ID'd as "BIGCHANGE" (ie, part of the main flash player on line 249) but simply replacing a different name for the video when it reaches the Flashvars "&file=Splash.flv" to something else to effect the change of video content I'm after, 'Olay.flv' I think. I have tried so hard to research into this but it just doesn't work. Is the problem to do with that :- 1) You can't ID something within <script>, ie BIGCHANGE in this instance. 2) innerHTML is only really for text replacement, not the amount of script I've stuck into it to replace within the whole <TD> cell with ID 'VID' (ie the main flash player) even though I've used delimiters and everything within the innerHTML data to try and not confuse it with apostrophes within speach marks, etc Any thoughts where I'm going wrong? Maybe Im barking up the wrong tree on this! Thanks so much guys for any headsup on a solution to this as I've been up all night for about a week on this! Dom Quote: <html> <head> <script type="text/javascript"> var a = january var b = febuary var c = march function test() { document.getElementById("test").innerHTML=a; <!-- needs to be A on first function click, b on second, c on third, etc..^^--> } </script> </head> <body> <p id="test"></p> <!-- the <p> should go to next month upon each function --> <input type="button" value="asdf" onclick="test()" /> </body> </html> I tried to explain it pretty well in the comment tags, thanks! hi i wants to change one input to texarea when i select one from radio, plz any suggestion how i would do that? my code PHP Code: <input type="text" name="other" value="this need to become textarea" /> <input type="radio" name="inputtext" />Text <input type="radio" name="inputtext" />Textarea so when i click inputtext radio name"other" will become a textrea rather then input type text. thanks for any help. Hi there, I'm working on a site: ocmd.co.nr And it features a lot of handy little web gadgets and apps for users. I was interested in creating a page, where two iframes are shown side-by-side both with the width of 50% and the height of 100%, with adressbars on top of each of them. So, essentially, what I need is just a code that allows the user to edit the iframe's src and get it to a different site. Still need assistance, thanks Okay, so here's an example code of what I'm needing: Code: <html> <head> <title></title> <style type="text/css"> #greenrow { background-color:#090; } #redrow { background-color:#F00; } </style> <script type="text/javascript"> if (calculate.level.value >= calculate.getElementById('shrimp').value){ class = greenrow; } else { class = redrow; } </script> </head> <body> <form name="calculate"> <table> <tr> <td><label> Level<input name="level" type="text" size="5" /></label> </td> </tr> <tr id="shrimp"> <td>Shrimp</td> <td align="center"><label> <input type="text" name="shrimp" /> </label></td> <td colspan="3" align="left">10</td> </tr> </table> </form> </body> </html> Okay so what I want to be done is to get information from the input text area "level" and IF "level" is >= 10...for this one certain row, I want it to get the class #greenrow. Else, class = #redrow. Thanks I'm trying to change a row of input fields to have the value(s) of a table row. When I click a button called Next, I want to pull in the value(s) that are already on the display. If I click Next again, I want to pull in the next row's values or if I click the button called Previous I want to get the prior lines values. Can someone please help or push me in the right direction? Thanks. Code: <script type="text/javascript"> function copyLine() { document.getElementById("pitem").value=document.getElementById("p1item").value; document.getElementById("ploc").value=document.getElementById("p1loc").value; document.getElementById("plot").value=document.getElementById("p1lot").value; document.getElementById("pqty").value=document.getElementById("p1qty").value; } </script> <table> <tr> <td><input type="text" name="item" id="pitem" size="15" value=""></td> <td><input type="text" name="loc" id="ploc" size="7" value=""></td> <td><input type="text" name="lot" id="plot" size="7" value=""></td> <td><input type="text" name="qty" id="pqty" size="10" value=""></td> </tr> <tr> <td><input type="button" value="Next" onclick="copyLine()"> <input type="button" value="Previous" /></td> </tr> <tr> <td id="p1item">Item 1</td> <td id="p1loc">Location 1</td> <td id="p1lot">Lot 1</td> <td id="p1qty">100</td> </tr> <tr> <td id="p2item">Item 2</td> <td id="p2loc">Location 2</td> <td id="p2lot">Lot 2</td> <td id="p2qty">200</td> </tr> <tr> <td id="p3item">Item 3</td> <td id="p3loc">Location 3</td> <td id="p3lot">Lot 3</td> <td id="p3qty">300</td> </tr> </table> Hi, I'm currently programming a menu editing script and I'm trying to reorder value of text input on change. What I'm trying to do is when I change the value of a text box it reorders the others. EX Start 1 2 3 4 5 Change 3->1 End 2 3 1 4 5 Here is what I've manage to do, it works only when the number is bigger. Javascript function Code: function changeOrder(current) { var num_name = current.name.split("_",2); var id = num_name[0]+"_"+num_name[1]+"_number"; var maxorder = document.getElementById(id).value; var currentmax = current.name.substr((current.name.length-1),1) if(currentmax <= maxorder && current.value > 0) { var start = (currentmax > current.value ? 1 : currentmax); for(var i=start;i<maxorder;i++) { var k = parseInt(i)+1; x = document.getElementsByName(num_name[0]+"_"+num_name[1]+"_order_"+k); x[0].value = i; x[0].name = x[0].name.substr(0,(x[0].name.length-1))+i; } current.name = current.name.substr(0,(current.name.length-1))+current.value; } } HTML input Code: <input type="text" style="width: 20px;" onchange="changeOrder(this);" value="1" name="other_title_order_1"> Thanks for any advices you may have Maxetime Hello guys, I've problem with connected database to textbox the value doesn't change. I tried with dropdownlist ,still the same problem. what's the best tool for it. var TextBox3 = document.getElementById("<%=TextBox3.ClientID %>"); var x = TextBox3.value; <asp:TextBox ID="TextBox3" runat="server" DataSourceID="SqlDataSource5" DataTextField="status" DataValueField="status"> </asp:TextBox> <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:RFIDConnectionString %>" SelectCommand="SELECT status from reader where reader_id=2"></asp:SqlDataSource> Thank you Hello, I am trying to change the value of #name and #category inputs based on the value of select. A friend gave me the code below, but I can't get it to work. Thanks so much for your help Code: <script type="text/javascript"> $('#Gift_Type').change(function(){ if ($(this).val() == 'Monthly'){ $('#name').val('Partnership') $('#category').val('Partnership') } else { $('#name').val('Donation') $('#category').val('Donations') } }) </script> Code: <SELECT NAME="sub_frequency" ID="Gift_Type" onchange="OnSelectionChanged (this)"> <OPTION VALUE="1m">Monthly</OPTION> <OPTION VALUE="">One Time</OPTION> </SELECT> Code: <input type="text" id="name" name="name" value="Partnership" /> <input type="text" id="category" name="category" value="Partnership" /> How do I change a text input's background when the user hits "Enter" or Key #13. The text-input field currently light's up to blue when hovered over, then it turns green when it is focused on, and now I want it to turn pink when you submit it. (This can be seen at http://ocmd.co.nr/ap) ------------------ Also, if anyone knows how I can redirect the user depending on there input, that'd be great. Regularly, it just runs a Google Search, but if I could get it so that when someone typed in, "chat room 1" for example, it'd open up a link or a new window w/ that. I'm trying to use an onclick function in a radio button to change the value of a hidden input in another form. What I want to happen is, when the user changes the value of the radio button (0 or 1), the value of the input named 'repeat' is set to 0 or 1 accordingly. The goal being that when I submit the form with input name='repeat' it will send the number indicated by the radio button. (Due to the structure of my page the radio button and the hidden input need to be two separate forms, but I don't think that should be a problem.) The code below isn't working -- the alert("changerepeat called") never even appears. It seems like the problem is that the onclick isn't even activating at all. Any ideas? Code: <script type="text/javascript"> function changerepeat(theval) { alert("changerepeat called"); document.forms[0].elements[0].value = theval; } function tellme() { alert("repeat = "+document.forms[0].elements[0].value); } </script> <form> <input type='hidden' name='repeat' value=''> <input type='button' value='tellme' onclick='tellme()'> </form> <form> <input type='radio' name='changerepeat' onclick='changerepeat(\'0\')'> 0 <input type='radio' name='changerepeat' onclick='changerepeat(\'1\')'> 1 </form> Thanks very much for reading! I have a problem thats above my head, im new to javascript. I want to be able to control the first three characters of an input string on a login form. If a user types GP15555 or JP15555 I want it to change to GPL5555 or JPL5555 respectively changing the "1" to an "L" on the prefix is this at all possible? any point in the right direction would be great. heres my code Code: </script> <script language="JavaScript" type="text/javascript"> //<![CDATA[ function Login(form) { var password = form.password.value; var pin = form.pin.value; var product = form.product.value; if (password) { var htsite = product + "/" + password + "/" + pin + "/index.html"; window.location = htsite; } else { alert("Please enter your password and pin."); } } // End --> //]]> </script> /thanks gp I wrote a function, to change a input value to show a key, which PHP later recognizes and makes addition changes too. However I can't seem to get this simple function to work, can you see anything wrong with it? Code: function quote(id) { var shout = document.getElementById('shout'); var currentShout = '; '.shout.value; var prefix = '@'.id; shout.value = prefix.currentShout; } I call it by Code: <a href="#" onclick="javascript: quote('2');">Comment</a> the input that changes is written as Code: <input id="shout" name="shout" type="text" onKeyPress="return submitenter(this,event);"> I am working on a job calculator. I have 2 txt input boxes titled "project_rate_field" and "project_time_field" as well as a third box .. "project_pay_total_field" for output.. I need to multiply the rate field and the time field and output the total into the third box. I've never really used javascript before so I dont know much about it or how to write it but im trying to learn. Here is my .js file ... Code: function project_pay_details() { var rate = document.getElementById("project_rate_field").value; var time = document.getElementById("project_time_field").value; var total = (rate * time); project_pay_total_field.value = "$" + total; } And here is my .html file Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script language="javascript" type="text/javascript" href="functions.js" /> <style> .wrap { float: right; } #project_pay { float: left; margin-right: 15px; line-height: 38px; font: 10px Arial, Helvetica, sans-serif; color: #bbb; } #project_pay_details { border-top: 1px dotted #ddd; padding-bottom: 10px; margin-top: 10px; float: right; width: 100%; } .field { border: none; line-height: 38px; font: 20px Arial, Helvetica, sans-serif; color: #666; width: 100px; font-weight: bold; margin-top: 6px; } </style> </head> <body> <form id="project_pay_details" name="form1" method="post" action="" class="editable"> <div class="wrap"> <div id="project_pay">Pay Rate<input type="text" name="project_rate_field" id="project_rate_field" class="field" value="10" />/ hr</div> <div id="project_pay">Total Hours<input type="text" name="project_time_field" id="project_time_field" class="field" value="0" /></div> <div id="project_pay">Project Total<input type="text" name="project_pay_total_field" id="project_pay_total_field" class="field" readonly="readonly" value="0" /></div> <input name="project_pay_details_refresh" type="button" value="Refresh" onClick="project_pay_details()" /></input> </div> </form> </body> </html> I need to know what im doing wrong because this obviously doesnt work. I have been working on this code for a few days now and it works. Or at least it appears to be working. I would like to have the tot 1, tot 2, tot 3 return with currency formatting. Is there a way to add something to my code to accomplish this? Thank you in advance for any suggestions. Regards Code: <html> <head> <script type="text/javascript" src="autoCurrency.js"></script> <script type="text/javascript"> function doCalc() { var v1 = document.getElementById('value1').value; var v2 = document.getElementById('value2').value; var v3 = document.getElementById('value3').value; document.getElementById('total1').value = ((v1*5)+(v2*1)) * (1-v3/100); document.getElementById('total2').value = ((v1*10)+(v2*1)) * (1-v3/100); document.getElementById('total3').value = ((v1*15)+(v2*1)) * (1-v3/100); } </script> <style type="text/css"> button { width: 80px; } input { margin: 10px 0; } input[type='text'] { width: 50px; } </style> </head> <body> <div> <input id="value1" type="text" value="0" /> <br /> </div> <div> <input id="value2" type="text" value="0" /> <br /> </div> <div> <input id="value3" type="text" value="0" /> <br /> </div> Tot 1:<input id="total1" type="text" /><br /> Tot 2: <input id="total2" type="text" /><br /> Tot 3: <input id="total3" type="text" /><br /> <button class="long" onclick="doCalc();">Calculate</button> </body> </html> Hi! I want to insert flash player on my page, that user can change flv source. But I dont know how to make input field that change flv source. I tried to insert input field and button but dont know how to make it working, please help me Here is my flvplayer embed code: <script type="text/javascript" src="http://flvplayer.com/free-flv-player/flvplayer/swfobject/swfobject.js"></script> <div id="embed_player"> <h1>Please Upgrade Your Flash Player</h1> <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p> </div> <script type="text/javascript"> var flashvars = { flvpFolderLocation: "http://flvplayer.com/free-flv-player/flvplayer/", flvpVideoSource: "http://flvplayer.com/media/audi_tdi_commercial.mp4", flvpWidth: "640", flvpHeight: "375", flvpInitVolume: "50", flvpTurnOnCorners: "true", flvpBgColor: "#FFFFFF" }; var params = { bgcolor: "#FFFFFF", menu: "true", allowfullscreen: "true" }; swfobject.embedSWF("http://flvplayer.com/free-flv-player/FlvPlayer.swf", "embed_player", "640", "375", "9.0.0", "http://flvplayer.com/free-flv-player/flvplayer/swfobject/expressInstall.swf", flashvars, params); </script> Hi! I am quite new to the world of JavaScript as I have done basic corse for it... and I have learnt that best way to understand it is to play around with it... but now I am stuck with on of the problem!! Problem: How can we assign text box input values by user to a variable and display that variable back on another element of the same HTML document(dynamically)... Conditions: The value has to be stored as a JavaScript variable only. No server-side script is to be used and has to be done locally. Please help! Hi guys, Let me explain simply what I do and what I'm trying to achieve: I got a couple of comboboxes were the user selects a series of numbers. Once a selection is made, the value is appended to an input box. The idea is that the appended values form a telephone number, or at least part of one, that will then be used to search trough a database to look for a matching number. The code below is what I have done so far: Code: <script type="text/javascript"> function displayIndicatif(){ var sel = document.getElementById("indicatif"); var text = sel.options[sel.selectedIndex].value; var out = document.getElementById("blabla"); out.value += text+"\n"; } function displayBloc(){ var sel1 = document.getElementById("bloc"); var text1 = sel1.options[sel1.selectedIndex].value; var out1 = document.getElementById("blabla"); out1.value += text1+"\n"; } </script> [...] <input type="text" id="blabla"/> [..] <select id="indicatif" onChange="displayIndicatif();"> <option value="021">021</option> <option value="022">022</option> <option value="031">031</option> </select> <select id="bloc" onChange="displayBloc();"> <option value="555" class="021">555</option> <option value="666" class="021">666</option> <option value="777" class="021">777</option> </select> Basically what happens now is this: combobox indicatif: 021 | 022 | 031 combobox bloc: 555 | 666 | 777 If I select "021" from indicatif, the script will append 021 to the input "blabla". The problem is, if I now select "022", the input will show "021022" instead of replacing the 021 with 022. What I would like is that, for each combobox, the script replaces the selected value with the new one instead of simply appending it, like instead of say 021022555666 it would show 021555 or 022666 or 021666 depending on what is selected...you get the idea? Is this doable? Needless to say I'm a total noob at javascript...I adapted the code I got now from some other guy who was trying to achieve almost the same thing and adapted it to my needs, or least, tried to, but now I'm stuck. Any help is appreciated! Thanks Hi there, I am a new javascript guy - struggling a bit but marching on - The following code works fine to set a form field - Code: document.getElementById("ZS_Land").value = (empLand.innerHTML); However, I changed to form field into a select with option list, and I need it to set an option from the select now - the select has the same name/id as the field had, but is not working Any ideas how I do that ? Many thanks in advance Glorifindal |