JavaScript - Outputting To Text Box
My script runs, but it prints out to a new window. I want it to appear in the text box in the Answer <div>. I've tried using document.my_form.Answer.answerText.write() and window.document.my_form.Answer.answerText.value = " "
I tried it with and without the <p></p> tags. I'm out of ideas. Can someone please help me figure this out? Code: <html> <head> <title>Magic 8 Ball</title> </head> <body> <form name="my_form"> <div id="question"> <h1>Ask your question here</h1> <input type="text" id="questionText" name="questionBox" /> </div> <div id="Answer"> <input type="submit" value="Submit" onClick="answer()"/> <h1>The magic 8 ball says:</h1> <script type="text/javascript"> function chance() { var ranNum = Math.floor(Math.random()*6); return ranNum; } function answer() { var nonsense = chance(); var reply = new Array(6); reply[0] = "Definitely"; reply[1] = "Quite possibly"; reply[2] = "Highly unlikely"; reply[3] = "Doubtful"; reply[4] = "No way!"; reply[5] = "Outlook is unclear, ask again later"; document.write('<p>' + reply[nonsense] + '</p>'); } </script> <input type="text" name="answerText" /> <input type="reset" value="Reset" /> </div> </form> </body> </html> Similar Tutorialsi still cant ouput correctly this php parse rss: PHP Code: $doc = new DOMDocument(); $doc->load('http://www.lepoint.fr/content/system/rss/a_la_une/a_la_une_doc.xml'); $count_items=$doc->getElementsByTagName("item"); //echo count($count_items); $title=$doc->getElementsByTagName("item")->item(0)->getElementsByTagName("title")->item(0)->nodeValue; foreach($count_items as $value){ echo "<table border='1'><tr><td>".$value->getElementsByTagName('title')->item(0)->nodeValue."</td><td>".$value->getElementsByTagName('description')->item(0)->nodeType."</td></tr>";} using this js code : Code: <style> div#RSS{width: 700px;height: 600px;border:1px solid gray;} </style> <script> PHPscript="<?php $doc = new DOMDocument();$doc->load('http://www.lepoint.fr/content/system/rss/a_la_une/a_la_une_doc.xml');$count_items=$doc->getElementsByTagName('item');$title=$doc->getElementsByTagName('item')->item(0)->getElementsByTagName('title')->item(0)->nodeValue;foreach($count_items as $value){echo '<table border=\'1\'><tr><td>\'.$value->getElementsByTagName(\'title\')->item(0)->nodeValue.\'<\/td><td>\'.$value->getElementsByTagName(\'description\')->item(0)->nodeType.\'<\/td><\/tr>';} ?>" function ClickRSS(){ document.getElementById("link").onclick=ShowRSS } function ShowRSS(){ div=document.createElement("div"); div.id="RSS"; div.innerHTML=PHPscript; document.body.appendChild(div); } window.onload=ClickRSS; </script> <body> <a href="#no" id="link">LINK</a> </body> Here are my Two classes and a tester. I need help outputting a sub-list of all the Highly Paid employees. public class Pay2 { private String name; private char gender; private double hours; private double payRate; /** * Constructor for objects of class Pay */ public Pay2(String n, char g, double h, double r) { // initialise instance variables name = n; gender = g; hours = h; payRate = r; } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public double computeGrossPay () { return hours * payRate; } public char getGender () { return gender; } public double getRate () { return payRate; } } _____________________________ import java.util.*; public class Salary { private ArrayList theSalary; public Salary() { ArrayList theSalary = new ArrayList (); } public void addSalary (Pay2 p) { theSalary.add (p); } public double computeSalary() { double total = 0; for (int i = 0; i < theSalary.size(); i++) { Pay2 p =(Pay2) theSalary.get (i); total = total + p.computeGrossPay(); } return total; } public double computeMale() { double total = 0; for (int i = 0; i < theSalary.size();i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getGender() == 'm') total = total + p.computeGrossPay(); } return total; } public double computeFemale() { double total = 0; for (int i = 0; i < theSalary.size();i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getGender() == 'f') total = total + p.computeGrossPay(); } return total; } public int highPay(double i) { double pay = i; int number = 0; for( int s = 0; s < theSalary.size(); s++) { Pay2 p =(Pay2) theSalary.get (s); if (p.getRate() >= pay) number++; } return number; } public ArrayList highPaid(double b) { double pay = b; ArrayList a = new ArrayList(); for (int i = 0; i < theSalary.size(); i++) { Pay2 p =(Pay2) theSalary.get (i); if (p.getRate() >= pay) a.add(p); } return a; } } _____________________________________ import java.util.*; public class Tester { public static void main (String [] args) { Salary s = new Salary(); Pay2 p = new Pay2("Bob", 'm', 30, 10.50); s.addSalary(p); p = new Pay2("Jen", 'f', 30, 12.00); s.addSalary(p); p = new Pay2("Tom", 'm', 20, 9.50); s.addSalary(p); p = new Pay2("Pat", 'f', 40, 15.65); s.addSalary(p); p = new Pay2("Nick", 'm', 45, 12.00); s.addSalary(p); p = new Pay2("Mike", 'm', 35, 15.00); s.addSalary(p); p = new Pay2("Barb", 'f', 20, 25.00); s.addSalary(p); p = new Pay2("Katie", 'f', 30, 14.00); s.addSalary(p); p = new Pay2("John", 'm', 45, 12.00); s.addSalary(p); p = new Pay2("Mark", 'm', 40, 7.75); s.addSalary(p); Scanner sc = new Scanner(System.in); System.out.println("What is the threshold for high Pay?"); double a = sc.nextDouble (); double w = s.computeSalary(); double m = s.computeMale(); double f = s.computeFemale(); int h = s.highPay(a); System.out.println("The weekly salarys for all employees is $" + w); System.out.println("The weekly salarys for all males is $" + m ); System.out.println("The weekly salarys for all females is $" + f); } } Any feedback will help. Thanks, Allusive Hi, I'm really new to javascript and need help. I have a table of ingredients and a number of times they appear in a product. the table looks something like this: ingredient_01 3 ingredient_02 5 ingredient_03 8 ingredient_04 7 I need to write a script/formula/anything that will generate an output where each ingredient is output as many times as the associated number. i.e. an output has to look like this: ingredient_01 ingredient_01 ingredient_01 ingredient_02 ingredient_02 ingredient_02 ingredient_02 ingredient_02 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_03 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 ingredient_04 Any help is appreciated. Thank you. I have the two functions below, I want to write a function that puts them into a chart, I have the chart sorted etc but just struggling with how to get the actual validated users inputs from these two functions into the chart, I've tried document.write('<td> $' + productIndex + '</td>'); into the chart but that wouldn't work anyway as there could be multiple inputs? Just need a way to get the output really. function getProductChoice(min, max) { var getProductChoice = function(min, max){ do{ var productIndex = parseInt(prompt('Enter your product choice; 0-5', '0')); } while( isNaN(productIndex) || productIndex < min || productIndex > max); }; getProductChoice(0,5); } function getProductQuantity(max) { do{ var productIndexQuantity = parseInt(prompt('How many would you like?', '0')); } while( isNaN(productIndexQuantity) || productIndexQuantity < 0 || productIndexQuantity > max); }; getProductQuantity(MAX_QUANTITY); I'm trying to insert a title and a body into a Google maps window through PHP. The body could contain double or single quotes. How do I output these so that they don't break the script? Relevant code: Code: $('#map_canvas').gmap('openInfoWindow', { 'content': '<strong><?php echo $m->marker->Title; ?></strong><br /><?php echo $m->marker->Body; ?><?php echo '<a href="./marker_info.php?id='.$m->marker->Nid.'"></a>' ?><br /><a id="m_location" href="#" data-role="button" data-icon="search" onclick="$.mobile.silentScroll(500);"></a>'}, this); Hi all, I have an issue that seems to relate to IE6 only. Tested and working in IE8 and FF3. If you go to the following page and click 'Buy Now' at the bottom of the page to submit the form the jQuery validate library error messages are displayed at the top of the page, rather than next to the corresponding form element: http://bit.ly/cc97GP Any help appreciated with this one. Seems to work fine in IE8 and FF3 as mentioned. Best Regards, Picco Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any help would be greatly appreciated! Code: <script type="text/javascript"> function loadText() { var t1=setTimeout("document.getElementById('data').innerHTML='<center><img style=\"margin-top:30px;\" src=\"loading.gif\" /></center>'",0000); var t2=setTimeout("document.getElementById('data').innerHTML='THEPAGE'",6000) } </script> The above is in the header, and I'm calling it in the html. Code: <script type="text/javascript"> document.write(loadText()); </script> in the page it displays properly, but then it also says "undefined" not sure why? anyone have any ideas? As of right now I have a code that will work in IE but wont work in FireFox...go figure. Basically what I want to have happen is when you type in an area code it will provide an output in a predetermined area of the page. For Example: Input- 512 Output - Austin, TX The code that I have doesn't work with firefox and I was just wondering if there was a code that would allow that to happen. Thanks! Hi, I have a form with 9 text fields and a text area. What I want to do is replace the text in the text area depending on how many fields contain text. For example my text boxes are named 1 to 9, if the user enters text in the first five boxes I want the text area to auto fill with 'you have selected boxes 1 to 5' if the user selects all nine it will say 'you have selected 1 to 9', therefore, the user must complete the text boxes in order. I have it working with an onchange event but i have a button on the form to also auto fill the text boxes and it does not work if this is clicked. Any help would be appreciated! Hi all, Thanks for reading. I'm having an issue trying to accomplish the following - I have a text field (field1) already displayed on the HTML page. However, there's a link where you can add additional text fields to the page as well. When the link is clicked, the second text field is added successfully (field2), and when the link is clicked again, the third text field (field3) is added successfully. However, the third field does not add itself to the page, and the text for anything greater than a third field also isn't displayed after. This obviously means that my "fields" variable is not working right, so I'm wondering, would anyone be able to assist me to help me get that variable processing correctly? Code: <script language="javascript"> fields = 1; function addMore() { if (fields = 1) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field2' size='25' /> <span>Field 2.</span>"; fields = 2; } else if (fields = 2) { document.getElementById('addedMore').innerHTML = "<input type='text' name='field3' size='25' /> <span>Field 3.</span>"; fields = 3; } else { document.getElementById('addedMore').innerHTML = "Only 3 fields are allowed."; document.form.add.disabled=true; } } </script> Here is the code in my HTML - Code: <input type="text" name="field1" size="25" /> <span>Field 1.</span> <div id="addedMore"></div> <p class="addMore"><form name="add"><a onclick="addMore()">Add another field.</a></form></p> Thank you very much. Hi, I have a form setup so that selecting a radio button opens a specific text field. The problem is if the user starts to enter information, then switches to a different radio button (perhaps they chose the wrong radio to start), the text they already started to enter on the previous textfield doesn't get cleared. This will be a problem later when inserting to sql. Here is a summary of the code: Code: <head> <script type="text/javascript"> function doClick(objRad){ if (objRad.value=="0"){ document.getElementById("textbox").style.display='block'; } else{ document.getElementById("textbox").style.display='none'; } if (objRad.value=="1"){ document.getElementById("textbox1").style.display='block'; } else{ document.getElementById("textbox1").style.display='none'; } if (objRad.value=="2"){ document.getElementById("textbox2").style.display='block'; } else{ document.getElementById("textbox2").style.display='none'; } } </script> </head> <body> <form action="insert.php" method="post"> <p>Please choose the business type: <input type="radio" name="rad" value="0" onclick="doClick(this)"> Sole Proprietorship <input type="radio" name="rad" value="1" onclick="doClick(this)"> Partnership <input type="radio" name="rad" value="2" onclick="doClick(this)"> Corporation <div id="textbox" style="display:none"> <input type="text" name="txt"> This is my sole proprietorship info.</div> <div id="textbox1" style="display:none"> <input type="text" name="txt"> This is my partnership info.</div> <div id="textbox2" style="display:none"> <input type="text" name="txt">This is my corporation info. </div> </form> </body> Any help is appreciated, Thanks in advance! Hello. I have a textarea where user can select a text then copy to clipboard (using EditArea script for highlighting) I need append additional information to the selected text so it won't be visible in the textarea, but only appear after copied to clipboard. For example: Code: text line one text line two text line three user selected word "two", hit CTRL+C to copy into clipboard (or used browser's context menu), but in clipboard it should be saved as: "selected word 'two'" What would be the approach? Thank you. Hi, I'm hoping this will be an easy one for you experts out there. I am working on a convention registration form. What I'm trying to do is have the text "50.00" pop into the COST field when any text (even if it's only one character) is entered into the NAME field. If the text in the NAME field is deleted, the "50.00" should also be deleted. Does anyone have a script that does this? Thanks! Hello there, this is my first post on this forum. I have learned a good bit of PHP and have implemented it for use in my work as a math tutor. My kids are telling me, however, that it is too inconvenient to hit tab or click on the next text box and would prefer to use the old style pencil and paper. I thought of a good idea: Javascript would be able to automatically focus the curser on the next text box if some condition was met. For example: 6+7. If the textbox reads 13, it will focus on the next text box. Otherwise, nothing happens. This kills three birds with one stone; the user will know if they got the question right or wrong and it will move automatically if they got it correct. The problem is I lack any real JavaScript wisdom. I would guess this would be quite simple. The closest thing I have found upon searching was this from the user requestcode, but this has to do with once the user has typed in 4 characters it moves automatically. Code: <SCRIPT LANGUAGE="JavaScript"> function nextbox(fldobj,nbox) { if(fldobj.value.length>3) {document.forms[0].elements[nbox].focus()} } </SCRIPT> </head> <body onLoad="document.myform.txt1.focus()"> <CENTER> <FORM NAME="myform"> <INPUT TYPE="text" NAME="txt1" SIZE="4" MAXLENGTH="4" onKeyUp="nextbox(this,1)"> Thank you for the help. im clueless when it comes to javascript, but this is what im trying to find: i have a page that has multiple text areas, i also have 4 links that when clicked i want to add some predefined text into the active text area the one with the text cursor in? The Hyperlinks: Code: <a href="#sc">Shift Changed</a> | <a href="#ol">On Leave</a> | <a href="#ot">OverTime</a> | <a href="#ss">ShiftSwap</a> The textareas: PHP Code: <td><textarea name=details$i rows=4 align=absmiddle cols=16 value="$details[$i]\">$details[$i]</textarea></td> as you can see the textareas are created on the fly based on a php array. would anyone be willing to put some code together for this? or even give me the basics on how i can get the active textarea's name so i can pass that to a script that inserts into a given field? Hi. I have developed a form all working fine but am struggling on the following. I need a checkbox for an item, when the checkbox is true the user can enter text in a text box, only if the checkbox is ticked. I have numerous items I need for this. Hope someone can help. Thanks Hi, Here's a sample form: Code: <form action="#" method="post"> Name:<br /> <input type="text" name="name" value="your name" /><br /> E-mail:<br /> <input type="text" name="mail" value="your email" /><br /> <input type="submit" value="Send"> </form> When you tab to a text input, the value gets highlighted. How can it be disabled? Any help is appreciated! Mike Hi again For instance I want to display some announcements from an external text file on a predefined box, like lets say 140 wide and height scalable according to text. The texts would be some announcements from me, a few words. I want the text justified and with previous / next link, if possible. And when they navigate to another page, they will get a random message in that box. There are news tickers on the net, but I just want something simple like this, no scrolling, fading, etc.. Has anyone a clue how I can accomplish that? Thanks. hey im new to javascript and im working in this function , i can't get it work here is my code PHP Code: <SCRIPT LANGUAGE="JavaScript"> function text(form1) { var j = document.form1.diary.value; j = j.italics(); document.form1.diary.value = j ; } </SCRIPT> whats the problem ? |