JavaScript - Outputting User Inputs From A Function Into A Table
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); Similar TutorialsHere's part of the code, problem I have is I have it set up for 5 rows, I need it to be able to make more than this, but not sure how many more, this is dependent on user input, how should I go about this? Also how would I go about making the users orders correspond with the right item number? I'd need to sort the array somehow? document.write('<table border="1">'); document.write("<tr>"); document.write('<th colspan="5">ORDER</th>') document.write("</tr>"); document.write("<tr>"); document.write('<th align="left">Item #</th>'); document.write('<th align="center">Name</th>'); document.write('<th align="center">Price</th>'); document.write('<th align="center">Quantity</th>'); document.write('<th align="center">Total</th>'); document.write("</tr>"); document.write('<td align="center">0</td>'); document.write('<td>' + productName[0] + '</td>'); document.write('<td> $' + sausagePrice + '</td>'); document.write('<td> ' + orderItemQty[0] + '</td>'); document.write('<td> ' + sausageTotal + '</td Hi, I am a complete beginner at Javascript(started a few days ago) and was having trouble with some functions. I'm trying to get the inputs required to change based on an option selected in a drop down menu. I was intending to run different scripts based on whatever is chosen but when I ran a test using an alert function, I realized my code isn't working. I went online and found really confusing stuff like "running a for loop through an array to make a dynamic select feature". Still confused any help would be appreciated. My code thus far: <html> <head> <title>Practice</title> <script language="javascript"> function myScript() { var loanType = document.form1.loan.options.text if (loanType == "Bank A") { alert("Working") } } </script> </head> <body> <form name="form1"> <select id="loan" name="loan" onchange="myScript"> <option></option> <option>Bank A</option> <Option>Bank B</Option> </select> </form> </body> </html> Reply With Quote 01-08-2015, 10:52 AM #2 Primus View Profile View Forum Posts New Coder Join Date Oct 2014 Posts 92 Thanks 0 Thanked 14 Times in 14 Posts Code: <script> function myScript() { var selectedIndex = document.form1.elements.loan.options.selectedIndex; // returns 0-2 in this case var loanType = document.form1.elements.loan.options[selectedIndex].value; // returns the value of the selected item if (loanType == "Bank A") { alert("Working") } } </script> <form name="form1"> <select id="loan" name="loan" onchange="myScript()"> <option></option> <option>Bank A</option> <option>Bank B</option> </select> </form> Maybe not the best way, but it does the trick. Reply With Quote 01-08-2015, 11:43 AM #3 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts You have quite a lot of obsolete code:- 1) It is obsolete to assign a name to a form and permitted only for the sake of backwards compatibility. 2) <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9). 3) Scripts should normally be placed right in front of the </body> tag. Any script can optionally go in the head if you wrap it inside a load event listener so that it can't run before the page loads. 4) Use the value of a select box option, not the text. 5) It is recommended that you place the opening brace following the function, if, else, for, while, do, switch, and try statements on the same line and not on the following line. Apart from that every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage. Code: <html> <head> <title>Practice</title> </head> <body> <form> <select id="loan" name="loan" onchange="myScript()"> <option value = "">Chosoe...</option> <option value = "Bank A">Bank A</option> <Option value = "Bank B">Bank B</Option> </select> </form> <script type = "text/javascript"> function myScript() { var loanType = document.getElementById("loan").value; if (loanType == "Bank A") { alert("Working") } } </script> </body> </html> If you really want to use the option text ... Code: <html> <head> <title>Practice</title> </head> <body> <form> <select id="loan" name="loan" onchange="myScript(this)"> <option value = "">Choose...</option> <option value = "Bank A">Bank A</option> <Option value = "Bank B">Bank B</Option> </select> </form> <script type = "text/javascript"> function myScript(element) { var loanType = element.options[ element.selectedIndex ].text; if (loanType == "Bank A") { alert("Working") } } </script> </body> </html> The Warrington players can hang their heads high. - Commentator, BBC Radio 2 Hi, I'm new here, and I'm a programming newb but am very interested in learning and possibly pursuing programming in the future. As such, I'm taking an intro to Javascript class at my university, and our homework is to make a function that when called upon makes a diamond out of *'s. It is supposed to do so by prompting a user for an int and then makes a diamond shaped object with the inputted number of stars in the middle of the diamond. an example of what this would look like (if a user entered in "5" to the prompt): *<br> ***<br> *****<br> ***<br> *<br> I am not sure how to set up this for loop, and have been trying so many different codes and have come nowhere close. Any help or insight would be so much appreciated. I apologize for all the text I'm about to type, but I just want to make sure I explain my problem in detail. So I have created a simple Weather Forecast algorithm containing the JavaScript code that uses a prompt to allow a user to enter a temperature in degrees Celsius, and based on the degrees entered (temperature scale is below), the program will display one of the following messages based on the selection structure I have created: (Kindly find attached .txt file of my entire code, I wasn't able to upload an HTML file.) -18 degrees Celsius: "Bundle up! It's freezing out there!" -18 - 0 degrees Celsius: "Pretty cold with a chance of snow!" 15 degrees Celsius: "Don't forget your jacket. It's still chilly out!" 16 - 27 degrees Celsius: "Perfect, lovely weather... unless it rains." 28 - 35 degrees Celsius: "Nice and warn. Go for a swim." 35 degrees Celsius: "Really hot! Best to stay in air conditioning." HELP Now i want improve on the same program and let the user enter the degrees in either unit using a prompt to ask the user whether the entry is Celsius(C) or Fahrenheit (F) (F scale is below) and use the correct degree breakdown to display the same messages: Less than 0 degrees Fahrenheit: "Bundle up! It's freezing out there!" 0 - 32 degrees Fahrenheit: "Pretty cold with a chance of snow!" 33 - 59 degrees Fahrenheit: "Don't forget your jacket. It's still chilly out!" 60 - 80 degrees Fahrenheit: "Perfect, lovely weather... unless it rains." 81 - 95 degrees Fahrenheit: " Nice and warn. Go for a swim." Greater than 95 degrees Fahrenheit: " Really hot! Best to stay in air conditioning." I'd appreciate if anyone can help me with this. Again, I've attached my original file where the user can only enter in degrees Celsius and gets the corresponding messages. I have tested it and it works perfectly. Attached Files hourlyForecast1.txt (954 Bytes, 24 views) Is it possible to have an input that points to some other function? For example: Code: function someFunction() { alert('It worked.'); } function doAnotherFunction(doIt, otherFunction) { if (doIt == true) { otherFunction(); } } <input type="button" value="test" onClick="doAnotherFunction(true, someFunction());"> Or would I need a switch statement and have all the various functions hardcoded? Hi, I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, Hi, I rarely use javascript so pardon my newbieness. I'm trying to create a function that is triggered by a <select> onchange event. It's supposed to save the newly selected value in a variable, then refer the user to a link location + variable. This is what I tried: Code: <script type="text/javascript"> function categoryRef() { var a = this.options[this.selectedIndex].value; document.location = 'recommend.php?cat=' + a; } </script> <select name="category" onChange="categoryRef()"> <?php $getCategoryQuery = "SELECT category FROM categories ORDER BY category"; $ConnectQuery = $database->query($getCategoryQuery); while($category = mysql_fetch_array($ConnectQuery)){ if($getCategory == $category['category']){ echo "<option selected='selected'>" . $category['category'] . "</option>"; } else{ echo "<option>" . $category['category'] . "</option>"; } } ?> </select> When I try this and change option nothing happens. Any pointers? My issue is that I have a javascript function applied on page load via an addLoadEvent function call in the head to every row (dynamic number of records retrieved) on a table. On every row of the table I also have an element (image or button) that performs a different function that is assigned on the element itself. Unfortunately, when I click the element it also performs the function that was applied to the row in the page load. Is there any way to not call this function on element click? I know usually you include code, but due to the nature of the work I am limited in that respect. Basically its: Code: <script type="text/javascript"> addLoadEvent(function() { function1(1); }) //function1 makes the table rows do something appearance wise. </script> <tr> <td></td> <td></td> <td> <img src="pics/delete.png" alt="Delete" onclick="function2();"> </td> </tr> I apologize if my post doesn't conform to the general guidelines of proper posting on this board. I'm new on this site. I am trying to use a user defined function and text area for a project, but nothing is showing up in the text area when i click the button. Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> function Greet() // Assumes: firstNameBox and companyName contain names // Results: writes a message with those names in messageArea { firstName = document.getElementById("firstNameBox").value; companyName = document.getElementById("companyNameBox").value; message = "To whom it may concern, my name is " + firstName + ", I am very interested in the job opening at, " + compnayName + ". I feel that I would greatly contribute to " + companyName + " success. I feel I fit the requirements needed to become an employee at " + companyName + ". I look forward to hearing from you."; document.getElementById("messageArea").value = message; } </script> </head> <body> <p> Enter your first name: <input type="text" id="firstNameBox" size="15" /> <br /> Enter the Company name: <input type="text" id="companyNameBox" size="15" /> </p> <p> <input type="button" value="Click for Greeting" onclick="Greet();" /> </p> <p> <textarea id="messageArea" rows="4" cols="40"></textarea> </p> </body> Hi, I'm very new to Javascript and I'm stuck. I am trying to create a js script that will prompt the user for a times table (example the 5 times table, the 7 times table, etc.) & prompt the user for 2 more values; the 'start' number and 'end' number. So there would be 3 numbers total the user must input. The script should present a 'warning' message if the user inputs letters or negative numbers. I have come very close to getting it too work but can't quite get past the last hurdle. Upon entering the 3 numbers, the output should look similar to this: (the 5 times table starting with 1 and ending with 12) The 5 times table 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50 5 * 11 = 55 5 * 12 = 60 I have placed the js script code on pastebin.com and below. The pastebin link is: http://pastebin.com/2NZPiFH9 Code: function writeTimesTable(timesTable, timesByStart, timesByEnd) { for (;timesByStart <= timesByEnd; timesByStart++) { document.write(timesTable + " * " + timesByStart + " = " + timesByStart * timesTable + "<br>"); } } var timesTable; while ( (timesTable = prompt("Enter the first number in the times table. Enter -1 to exit.", -1)) != -1) { while (isNaN(timesTable) == true) { timesTable = prompt(timesTable + " is not a valid number, please retry.",-1); } if (timesTable == -1) { break; } document.write("<br>The " + timesTable + " times table<br>"); writeTimesTable(timesTable,1,12); } 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> Hi, Thank you for helping me and also read my post. Anyone know how to make a function of below request?. 1)Textarea for input text 2)Button for submit text 3)Submitted text into table 4)All the text into table one by one what i need help is 1) How to separate each word or text to table cols or rows 2) How to auto add another cols or rows once the text submit by Textares 3) How to separate each table th or tr by ID or Name like below Code: <table border="1"> <tr> <th>First</th> <th>scoend</th> <th>third</th> </tr> <tr> <td id="1">1</td> <td id="2">2</td> <td id="3">3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> </table> Thank you so much. i 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> 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> 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. Hi All, I am working on a script that creates a table, taking the data from a number of text fields and populating the table cells with it. Originally I had to start with an existing table containing one blank row but I was able to get the script to create the table dynamically. Unfortunately I seem to have broken my delete row function (this was working fine when the script started with an existing table). The error I am getting is: TypeError: 'cells.0.childNodes' is null or not an object I googled this but could not find anything to help. I don't have alot of javascript experience and need help from the experts. Thanks in advance for all your help guys! Kind regards, Ken 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 src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> </style> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> </head> <SCRIPT language="javascript"> function addRow(tableID) { if (!document.getElementById(tableID)) { //alert("the table does not exist"); var body = document.getElementsByTagName("body")[0]; // creates a <table> element and a <tbody> element var tbl = document.createElement("table"); var tblBody = document.createElement("tbody"); var newRow = document.createElement("tr"); // add the row to the end of the table body tblBody.appendChild(newRow); // put the <tbody> in the <table> tbl.appendChild(tblBody); // appends <table> into <body> body.appendChild(tbl); // sets the id of "dataTable" and border attribute of tbl to 0; tbl.setAttribute("id", "dataTable"); tbl.setAttribute("border", "0"); } var StartTime = document.getElementById('StartTime'); var EndTime = document.getElementById('EndTime'); var MaterialID = document.getElementById('MaterialID'); var Title = document.getElementById('Title'); var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; cell1.appendChild(element1); var cell2 = row.insertCell(1); var element2 = document.createElement("input"); element2.type = "text"; element2.setAttribute("name","StartTime[]"); element2.value = StartTime.value; cell2.appendChild(element2); StartTime.value=""; var cell3 = row.insertCell(2); var element3 = document.createElement("input"); element3.type = "text"; element3.setAttribute("name","EndTime[]"); element3.value = EndTime.value; cell3.appendChild(element3); EndTime.value=""; var cell4 = row.insertCell(3); var element4 = document.createElement("input"); element4.type = "text"; element4.setAttribute("name","MaterialID[]"); element4.value = MaterialID.value; cell4.appendChild(element4); MaterialID.value=""; var cell5 = row.insertCell(4); var element5 = document.createElement("input"); element5.type = "text"; element5.setAttribute("name","Title[]"); element5.value = Title.value; cell5.appendChild(element5); Title.value=""; } function deleteRow(tableID) { if (document.getElementById(tableID)) { //alert("the table exists"); try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } } </SCRIPT> <body> <span id="spryStartTime"> <label for="StartTime">Start Time:</label><br /> <input name="StartTime" type="text" id="StartTime" tabindex="1" size="10" maxlength="8" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br /> <label for="EndTime">End Time:</label><br /> <span id="spryEndTime"> <input name="EndTime" type="text" id="EndTime" tabindex="2" size="10" maxlength="8" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span><br /> <label for="MaterialID">Material ID:</label><br /> <span id="spryMaterialID"> <input name="MaterialID" type="text" id="MaterialID" tabindex="3" size="10" maxlength="10" /> <span class="textfieldRequiredMsg">A value is required.</span></span><br /> <label for="Title">Title:</label><br /> <span id="spryTitle"> <input name="Title" type="text" id="Title" tabindex="4" size="50" maxlength="50" /> <span class="textfieldRequiredMsg">A value is required.</span></span><br /> <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /> <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" /> <script type="text/javascript" /> var sprytextfield3 = new Spry.Widget.ValidationTextField("spryStartTime", "time", {validateOn:["blur"], format:"HH:mm:ss", useCharacterMasking:true}); var sprytextfield4 = new Spry.Widget.ValidationTextField("spryEndTime", "time", {format:"HH:mm:ss", useCharacterMasking:true, validateOn:["blur"]}); var sprytextfield5 = new Spry.Widget.ValidationTextField("spryMaterialID", "none", {validateOn:["blur"]}); var sprytextfield6 = new Spry.Widget.ValidationTextField("spryTitle", "none", {validateOn:["blur"]}); </script> </body> </html> 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 to All, I have a table that contains many rows, some in italian with code <td nome='riga_i'> and some in english with code <td name='row_e'>. I have created two buttons with different background flags: italy and uk, so when one pushes the button with flag uk, the html page will be reloaded with only english rows, and when one pushes the button with flag it, the same page is reloaded containing only italian rows. All the code posted here works well, but I think that the code can be better because to reach this result I had to dupplicate the same function and I don' t like this. Here the code: <html> <head> <script type="text/javascript"> function toggle(name) { tr=document.getElementsByTagName('tr') for (i=0;i<tr.length;i++){ if (tr[i].getAttribute(name)){ if (tr[i].style.display=='none'){tr[i].style.display = '';} else {tr[i].style.display = 'none';} } } } // function toggle(nome) { tr=document.getElementsByTagName('tr') for (i=0;i<tr.length;i++){ if (tr[i].getAttribute(nome)){ if (tr[i].style.display=='none'){tr[i].style.display = '';} else {tr[i].style.display = 'none';} } } } </script> </head> <body onload="toggle('name');"> <table> <tr nome="riga_i"> <td>REQUISITI RELATVI AL SERVIZIO</td> <td> </td> <td><input type="button" onclick="toggle('nome');toggle('name');" style="background-image: url(../images/flag_uk.jpg); background-color:Transparent;" /></td></tr> <tr name="row_e"> <td> </td> <td>REQUIREMENTS RELATED TO THE SERVICE</td> <td><input type="button" onclick="toggle('name');toggle('nome');" style="background-image: url(../images/flag_italy.jpg); background-color:Transparent;" /></td></tr> .... .... and so on.... ..... </table></html> To better the code I have tried in this way but without success ... <html> <head> <script type="text/javascript"> function toggle(this) { if (this=='nome' || this=='name'){ tr=document.getElementsByTagName('tr') for (i=0;i<tr.length;i++){ if (tr[i].getAttribute(this)){ if (tr[i].style.display=='none'){tr[i].style.display = '';} else {tr[i].style.display = 'none';} } } } } </script> </head> Thanks in advance !!! Hi All, I have a button in my html form that will process some functions when user clicks on the button. The problem is after processing the functions, the result is not displayed in the form where I want it to be displayed. I want to ask whether we can create table in the function and display the result in the table row/column but in the same form. Is this possible to be done? And how to do this? In this form cpiM, the input button will call function showIndex. Code: <tr> <td><input type="button" value="Enter" onclick="showIndex(document.cpiM.currFrom.options.selectedIndex, document.cpiM.currTo.options.selectedIndex, document.cpiM.base.options.selectedIndex, document.cpiM.country.options.selectedIndex)"> </td> <td><input type="button" onclick="frmResetM()" value="Reset form" /> </td> </tr> In this function, I want to display the result of calcIndex right below the button Enter in the form cpiM. Code: function showIndex(frm, to, base, country) { for (i=frm; i<=to; i++) { document.write(calcIndex(i, base, country)); document.write("<br/>"); } } |