JavaScript - Javascript Function To Write To A Input Text Box
Hello:
I have two input boxes on a form which receive the first and last name of a user. I want to be able to use charAt() to get the first letter in each box and pass it to a third box on the same form. Is this doable? May I request some help? I was thinking something like the function below would be the starting point --I stand correct, as it is not working. Code: <script type=\"text/javascript\"> var str=\"Mossa\"; <!--document.write(str.charAt(0));--> document.write('<INPUT TYPE=text size=2 VALUE=\"str.charAt(0);\">'); var str=\"Barandao\"; document.write('<INPUT TYPE=text VALUE=\"str.charAt(0)\">'); <!--document.write(str.charAt(0));--> </script> Any thoughts! Mossa Similar TutorialsHi, I was hoping you could help me, I was wanting to write text to the screen but without re-writing the whole screen (e.g. document.write();. I wish to take text and put it in a function, modify it, then display it. So far I have: Code: <script type = "text/javascript"> function calculate(text){ var x = "10.0"; var gpa = text.replace(/0.0/g,x); document.getElementById("text").innerText=gpa; } </script> <p id = text >Your Grade Point Average (GPA) is: 0.0</p> <button type="button" onclick="calculate(text)">Calculate</button> Your help would be really appreciated write a function that when called will ask the user for a series of numbers to be entered 1 at a time and then calculates their sum,their average,and their average rounded up then output the results. for example the average of a series of numbers is found by adding the numbers together and dividing by the amount of numbers entered (so the average of 2,5,1 and 7 is equal to (2+5+1+7)/4=15/4=3.75). I need javascript to read height of an static multiline text and write height value into the var value? Is it possible? Hello, I use a iplocator api, which is javascript and gives out the city name, country and zipcode output PHP Code: <script language="JavaScript" src="http://www.somesite.com/somefile.js?key=apikey"></script> <script language="JavaScript"> <!-- document.write(ip2location_isp() + ', ' + ip2location_city() + ', ' + ip2location_zip_code() + ', ' + ip2location_net_speed()); //--> </script> my question or where i need help is that, i would like to output each of those as a hidden text field, so later i can store into mysq database with POST method from the hidden field. thank you in advance for your time n help This is hopefully a simple fix and I hope someone can help me out, I'm pretty new at coding. I have a form on an html page and I want to make it so when a button is clicked, it adds one to the input to the right of it, and when a button to the right of the input is clicked, it will delete one to the left of that button. I don't want to resort to making a new function for each and every form, because there will be a lot. Here is the form and input parts: Code: <form name="calculate"> <input type="button" onClick="add()" /> <input name="result" type="input" readonly="readonly" value="0" /> <input type="button" onclick="sub()" /> </form> Here is what the function code looks like: Code: function add() { var add = 1 * calculate.name.value; add = add + 1; calculate.name.value = add; } function sub() { var add = 1 * calculate.name.value; add = add - 1; calculate.name.value = add; } Note: where I called the calculate.name.value, that obviously doesn't work, and I need some way, rather than making multiple functions and changing the name part, to be able to call to a name near the button, if at all possible. Any and all ideas are appreciated, Thanks! how would you make when you press a button it writes somthing in a input box.
this had to do wiht HTML and javascirp thow would you make a function that wirtes somthing in a input box(sorry about messy ness i wasint looking)
Hey guys, First shot at JS so please be gentle! I'm trying to get this script to clear the default value of my input elements on focus. It works well the first time, however, if a user inputs some fresh text, selects something else, then selects the same input element again, it will clear the text they entered. Make sense? Here's the script (thanks in advance!!): Code: <script language="JavaScript"> function clickFocus(input){ input.className = 'focus'; if (input.value = input.defaultValue){ input.value = ''; } } function unFocus(input){ input.className = 'entered'; if (input.value == ''){ input.value = input.defaultValue; input.className = 'normal' } } </script> <form action="confirmation.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return checkForm(this)"> <input type="text" name="name" value="Name" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="email" value="Email" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="subject" value="Subject" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <textarea type="text" name="message" onfocus="clickFocus(this)" onblur="unFocus(this)" rows="5">Message</textarea> <input class="submit" name="submit"type="submit" value="Send Message" /> </form> Hello. My goal is for the user's input on their first visit to redirect their landing page in the future. I am a novice and any help is very much appreciated. The form's drop down menu includes three cities (Calgary, Toronto, Vancouver). When the user presses "submit form", the script should create a cookie to store the user's city selection. Next time the user visits the site, they should be redirected to their city's site, ie. "/vancouver.html" Right now, the code is returning an error from the onload("redirect();") function. The error indicates I am trying to redirect to "/[object HTMLSelectElement].html", but I am not sure if the trouble is in reading or writing the cookie. For simplicity, I've removed most of the other content from this page (my cookie.js is attached as a .doc): Code: <title>Site Title</title> <script type="text/javascript" src="cookie.js"></script> <script language="JavaScript" type="text/javascript"> function redirect() { userCity = readCookie ("user_city"); if (userCity) { window.location.replace(userCity + ".html"); } else { window.location.replace("index.html"); } } function setCity(box) { { var userCity =(document.welcomeSignUp.userCity); for (i=0; i<userCity.length; i++) { if (userCity[i].name != box.name) { userCity[i].selectedIndex = 0; } } } writeCookie("user_city", userCity, 5 * 365); } </script> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <form id="welcomeSignUp" action="" method="get" name="welcomeSignUp" onload="redirect();"> Your Email address: <input type="text" name="email" value="" size ="20" /> <br /> Choose Your City: <select name="userCity" size="20"> <option value="one">Calgary</option> <option value="two">Toronto</option> <option value="three">Vancouver</option> </select> <a href="index.html"><button class="rounded" onclick="setCity(this);"> <span>submit form</span> </button></a> </form> </body> </html> I followed the tutorial below and got my image fade to work: http://clagnut.com/sandbox/imagefades/ Now I want to have text become visible once the fade is done. I can't get it to work. style portion: .enhanced { visibility:hidden; } javascript functions: <script language="javascript"> document.write("<style type='text/css'> ##thephoto {visibility:hidden;} </style>"); window.onload = function() {initImage()}; function initImage() { imageId = 'thephoto'; image = document.getElementById(imageId); setOpacity(image, 0); image.style.visibility = 'visible'; fadeIn(imageId,0); } function setOpacity(obj, opacity) { opacity = (opacity == 100)?99.999pacity; // IE/Win obj.style.filter = "alpha(opacity:"+opacity+")"; // Safari<1.2, Konqueror obj.style.KHTMLOpacity = opacity/100; // Older Mozilla and Firefox obj.style.MozOpacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3 obj.style.opacity = opacity/100; } function fadeIn(objId,opacity) { if (document.getElementById) { obj = document.getElementById(objId); if (opacity <= 100) { setOpacity(obj, opacity); opacity += 10; window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 150); } if (opacity = 100) { textId = 'enhanced'; text = document.getElementById(textId); text.style.visibility="visible"; } } } </script> I have added this to the last function: if (opacity = 100) { textId = 'enhanced'; text = document.getElementById(textId); text.style.visibility="visible"; } But the text appears instantly. I want to be able to display the whole contents of a text file containing 4 paragraphs of text, on a static web page, as soon as a video finishes playing on the page. The video is to be set to autorun as soon as the page loads in the browser. The text file mentioned above, is to remain hidden when the page initially loads and the video is playing. Please I need your advice about what JavaScript code to use to achieve this effect, and where to place the code in the HTML code of the web page. I am new to website design and the use of JavaScript code. I have seen examples of code used for the timed delay of the display of an image file, after a video has finished playing. I do not know how to apply this to the display of a text file. I do not want to convert the whole text file into an image file, as I feel this would negatively affect the search engine optimisation of the page, if there is no text content on the page. Thank you. Is there a way to call javascript functions based on the text between a span element? In other words if I have <span id="mySpan">Bronze</span> then it will call a javascript function but if I have <span id="mySpan">Silver</span> then it will call a different function? Thanks! Hi all can someone guide me (total JS newbie) on this presumably pretty easy task? I have a "parent" page with some text inputs in it (a form). This is what I am after: -when the user clicks a link it pops open a new window via JS - "child" (this is working). -in the "child" window there are also some text inputs (another form) (done). -when the user changes the value for 'testChild_textInput_4' in the child window, then I want it to automatically set this same value, to effectively overwrite, what is currently in 'testParent_textInput_2' in the parent window. Presumably this involves an onChange event, but it is also OK with me if the needful (the text input's value in the parent window being overwritten) happens upon the child window's form submit. If anyone can show me either trick, I would be thrilled! I set up a test page to make this all easy to talk about: http://www.yellow-turtle.com/testDumpMe_parent.html Please let me know! Thanks! -John I am thinking this should be fairly easy but yet I am not getting far. I want to have a form with a single text imput field for a zip code. Depending on which zip code the user enters will determine which url they will be sent to. If they enter a zip code which is not in the script, they would be sent to a default url. I am also assuming this can be accomplished with javascript. Any help is greatly appreciated. Hi All, I have a problem in which I try to execute a funcition via a document.write() and it throws an "object expected" error. Overall I am making an interface for MS ACCESS .mdb table via ADODB using JavaScript and I want to be able to click on a link and the id is used to delete that entry. Code: My function is: Code: function deleteRecord(del) { var adoConn = new ActiveXObject("ADODB.Connection"); var adoRS = new ActiveXObject("ADODB.Recordset"); adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = {path to }knowBA.mdb'"); adoRS.Open("Select * From know where ID="+ del, adoConn, 1, 3); adoRS.Delete; adoRS.Close(); adoConn.Close(); } The code using the funcition is - oh and the numric KEY is rs(0) : Code: if(!rs.bof) { document.write("<table width='700' border='1' align='center' cellpadding='2' cellspacing='0' bgcolor='#FFFFFF'>"); rs.MoveFirst() while(!rs.eof) { document.write("<tr><td><div align='center'><strong>"+rs(1)+"</strong></div>"); document.write("<strong>Keyword(s):</strong> "+rs(3)); document.write("<br><strong>Entry:</strong> " +rs(2)+" "); document.write("<A HREF='javascript:onClick=("+"eval(deleteRecord(" +rs(0)+"))"+")'>delete</A> "); document.write("</td></tr>"); cnt=cnt+1; rs.MoveNext() } document.write("</table></form>"); } if (cnt==0){ alert ("Sorry, there are no results on that search.");} rs.close() cn.Close(); } </script> Thanks for any hints on how to accomplish this! So Im trying to make it so my button writes in one box when I click it one time, another when I click it a second, etc, but when I click it once, it writes in all boxes. Why is this? Code: content += "<br><input type='text' value='' id='d1' name='d1'><br>" content += "<input type='button' value='random card' id='r1' name='r1' onclick='randomCard()'>" content += "<div id='c1' name='c1'></div><div id='c2' name='c2'></div><div id='c3' name='c3'></div><div id='c4' name='c4'></div><div id='c5' name='c5'></div><div id='c6' name='c6'></div><div id='c7' name='c7'></div><div id='c8' name='c8'></div><div id='c9' name='c9'></div><div id='c10' name='c10'></div><div id='c11' name='c11'></div>" function checkValue(){ if (c1.innerHTML == ""){ c1.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML == ""){ c2.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML == ""){ c3.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML == ""){ c4.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML == ""){ c5.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML == ""){ c6.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML == ""){ c7.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML == ""){ c8.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML == ""){ c9.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML == ""){ c10.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML == ""){ c11.innerHTML = "<img src='"+cUrl+randCard[0]+cExt+"' alt='"+randCard[1]+"'>" } else{ if (c1.innerHTML != "" && c2.innerHTML != "" && c3.innerHTML != "" && c4.innerHTML != "" && c5.innerHTML != "" && c6.innerHTML != "" && c7.innerHTML != "" && c8.innerHTML != "" && c9.innerHTML != "" && c10.innerHTML != "" && c11.innerHTML != ""){ alert('How in the **** did you get more than eleven cards?') } else{ } } } } } } } } } } } } } function randomCard(){ for (c=0;c<DCard.length;c++){ randCard = DCard[Math.floor(Math.random()*DCard.length)] document.getElementById('c1').value = randCard c1 = document.getElementById('c1') c2 = document.getElementById('c2') c3 = document.getElementById('c3') c4 = document.getElementById('c4') c5 = document.getElementById('c5') c6 = document.getElementById('c6') c7 = document.getElementById('c7') c8 = document.getElementById('c8') c9 = document.getElementById('c9') c10 = document.getElementById('c10') c11 = document.getElementById('c11') checkValue() } } Not my whole code, but the necessary parts. Is there a javascript code so that you can disable a textarea but parts of the page can still add to the textarea if your peter i mean about the other javascripts you told me. Sorry if this is confusing just ask me and i will rewrite it
Is there any possibility to write a text file using Chrome/FF? On the other words, writing a text file w/o using ActiveX. Thank you.
Hi, New to JS. Have ordered some new books, but need to get somethings going in the mean time. What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart. [/CODE] <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> [/CODE] So then the wheels came off and in response, began to simplify what was trying to be done to find where the issues were. As far as I can get working is: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> <script type="text/javascript" > function myFunc() { alert("is this working"); } </script> </head> <body> <input id="input1" name="input1" type="text" onkeyup="myFunc()" maxlength="2" value="type a No." /> </body> </html> First issue with this: When I first get to the page everything is just as ordered. The focus is on the text box and the default value is "type a No." When I press a key onkeyup, I bring up the alert box with "is this working" in it. But when I refresh the page with the refresh button, after clicking the "ok" on the alert box, the character that was typed in is still displayed. If I use the link to the page, or the URL from the address bar, then the page reloads properly with the default value, "type a No". Question 1: How do you get the default textbox value using the refresh button as apposed to reloading the page using a link or from the address bar? Using Firefox 8.0 Second and more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I'm doing something wrong on a concept level. NOTE: changed the default value of the text box to " ". Looked like to me there was an issue with the size specification and the default string length as you could only enter in a key stroke by highlighting the text and replacing it Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" > window.onload=function() { document.getElementById("input1").focus(); } </script> <script type="text/javascript" > function myFunc(awe) { alert(awe); } </script> </head> <body> <input id="input1" name="input1" type="text" onkeyup="myFunc("123")" maxlength="2" value="" /> </body> </html> Question 2: can someone straighten me out with this? I would like to know how to do things. 1. I would like to know how i would code a javascript so if i edit the text inside of either a certain div or in the javascript document itself (which ever would work, would like to have it take the text from a div but not too picky) and then have it write that text in other parts of the same page and other pages by like putting a javascript code in it's place or however you would do it. Basically if i write "hello world" in the div/javascript document, it will write "hell world" in multiple places just from me editing that one part. ok so help with this would be awsome. My second thing. 2. I would like to take and use some javascript function, such as document.write or what ever to do pretty much the same thing as my first thing as my first problem, but with a div, for like a navigation bar or etc. So any help would be greatly appreciated! =) THANKS! |