JavaScript - Two Simple Questions Prolly Really Easy
number 1
why does my lab5.php hate me? number 2 what do you think of my code thus far? Any suggestions? (go easy on me I'm new at this) http://opentech.durhamcollege.ca/~in...rittains/labs/ PHP Code: <![CDATA[ Name: Shelby Class: INTN2201 Date: March 08, 10 4:31AM (My B-day) (No I didnt procrastinate I just finally figured out my include problem...) Description: do I actually have to describe this? ]]> <img src="images/logo.jpg" height="300px" /> <h1>Lab5</h1> <table> <style type="text/css"> td, th, table { border: 1px solid red; } </style> <tr> <th>Celcius</th> <th>Fahrenheit</th> </tr> <?php for($i= -4; $i<=10; $i+=1) { $j = $i*10; $k = (9.0/5.0*($i*10) + 32); echo "<tr><td>"; echo $j; echo "</td><td>"; echo $k; echo "</td></tr>"; } ?> </table> <br /><br /> <a href="http://www.durhamcollege.ca">Durham College</a> <br /> <a href="http://www.durhamcollege.ca"><img src="images/dc_fullcolour.jpg" height="100px" width="250px" alt="Durham College Logo" /></a> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /> </a> </p> Similar Tutorials1. I want to make form with 2 select filds that one of them will be disabled if in the first the use choose a specific option i wrote it in this way (but its not work) how I fix it? Code: <script type="text/javascript"> function itay() { if (document.some1.one.value="x") document.some1.two.disabled=true if (document.some1.one.value="y") document.some1.two.disabled=false } </script> </head> <body bgcolor="#FFFFFF"> <form name="some1"> <table> <tr> <td> <select id="one" onclick="itay()"> <option value="x">x</option> <option value="y">y</option> </select> </td> <td> <select id="two"> <option value="a">a</option> <option value="b">b</option> </select> </td> </tr> </table> </form> 2. I want that after u fill the form and press submit u will see a txtarea with all the options u selected (for confirm that you chose the right things) and then press submit agien and get all the things u saw in the txtarea to a Email. (Hope u understand ) so how I do it? Hello! I have a few simple questions and I'm not having any luck with my Google searches. Any information is appreciated! Pardon my pseudo-coding... It's the simplest way to describe what I'm looking for. 1. I have a two dimentional array called List. I want to write a for loop to loop through the first dimension of the array. How is this done? Code: for (Line in List[][]) { write ( List[Line][1] + " = " + List[Line][2] + "<br/>"); } 2. Is there a simple example of how to create and use an object with multiple properties, functions, etc? For example, the following "person" object: Code: Person as object - property FirstName as string - property LastName as string - function Name = property FirstName + " - " + property LastName - property Children[] as array of Person objects - property Gender as string - property Mate as Person object - property DOB as date 3. Can enumeration be done easily in Javascript? Code: enum StatusFlags blank as 0 new as 1 free as 2 reserved as 4 sold as 8 endedum enum StatusDecoration new as "bold" old as "normal" free as "green" notfree as "red" reserved as strikethrough"" unreserved as "no-strikethrough" sold as "italics" unsold as "no-italics" endenum Thanks! I have a bunch of questions and know very little javascript. (I come from a world of Visual basic) I would spend the time to learn a lot more about it, but i dont have that time since this program needs to be done by tuesday. Question 1: Do i save the text from textbox a user inputs to a variable like this when a submit button is clicked?: var tb1=textbox1.text Question 2: To activate or call that variable on the click of a button do i do this?: <form> <input type="button" value="text" onlick="tb1"/> </form> I have a bunch of questions, but i will ask them later when i know how to state them better. Short version at bottom Need to add an array before an array to init thousands of arrays. Mostly worked out, just need to add an array before an array. ........Please check it out. Really want to finish this tonight or tomorrow. Alright, so two days later I finally have this portion working but its only because of the awesome people of this forum and unforunately these people thought I had some half decent grasp of javascript (which I don't) and so their answers were meant to solve my problem but each time I was left with no idea how to repeat what they did. So, I've learned a lot of extra stuff that I really could have done without in the effort to try and understand what they did. This is all well and good because I'm much farther than I am had I gone it alone (so thank you!) but please, anyone that posts an answer, could you try and explain a bit of how I might use your solution again. For example, today I was confused for about an hour because I didn't understand how [CODE]var newArray=[], a, i=0;CODE] worked but only after staring at it long enough and not finding anything on google related to "values inputed after array initialization" did I finally realized that these were not params of a new array but just new variables. Code: var alphabetArray =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','all1']; var a; var i=0; while(a=alphabetArray[i++]){ eval('var _img_'+a+' = []'); eval('var _h_'+a+' = []'); eval('var _r_'+a+' = []'); eval('var _m_'+a+' = []'); eval('var _yt_'+a+' = []'); } alert(_h_all1) and its working perfectly but I somehow I need to add Code: var pageNum = ['','p2_','p3_','p4_','p5_','p6_','p7_','p8_','p9_','p10_'] need to add pageNum to every alphabetArray so... _img_a = [],_img_p2_a = [], img_p3_a = [].... _img_p10_a = [] repeated for every variable in alphabetArray. _yt_p10_all1=[] Super short version Code: var alphabetArray =[letters/numbers]; var a; var i=0; while(a=alphabetArray[i++]){ eval('var _img_'+a+' = []'); } // works now I need to add 10 page prefixes before each var in alphabetArray Code: var pageNum = ['','p2_','p3_','p4_','p5_','p6_','p7_','p8_','p9_','p10_'] need to add pageNum to every alphabetArray so... _img_a = [],_img_p2_a = [], img_p3_a = [].... _img_p10_a = [] repeated for every variable in alphabetArray. _yt_p10_all1=[] Please explain how this might be possible in a way that your dog might understand. hey guys im trying to make something that selects two different images but it keeps selecting two images that are the same, and dont know how to go about it to make it select two different. please help 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/javascript; charset=utf-8" /> <title>Untitled Document</title> <script language="JavaScript"> <!-- var theImages = new Array() theImages[0] = '100.jpg' theImages[1] = '200.JPG' theImages[2] = '300.JPG' theImages[3] = '400.jpg' var j = 0 var p = theImages.length; var preBuffer = new Array() for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1)); function showImage(){ document.write('<img src="'+theImages[whichImage]+'">'); } //--> </script> </head> <body> <div align="center"></div> <table width="996" height="511" border="1"> <tr> <th scope="col"><script language="JavaScript"> <!-- showImage(); //--> </script> or <script language="JavaScript"> <!-- showImage(); //--> </script> </th> </tr> </table> </body> </html> I have written the following code which returns a simple times table. The problem is that I want the resulting times table written to the div id=results section in the body of the html page rather than writing it to another page. I hope that makes sense! Thanks in advance for any help. <html> <head> <script type="text/javascript"> function timestable() { var num = parseInt(document.timesForm.times.value); var counter = 1; while (counter<=12) { document.write(counter+" X "+num+" = "+counter*num+"<br />"); counter++; } } </script> </head> <body> <form id="timesForm" name="timesForm"> <p>Enter the number he <input type="text" id="times" /></p> <p> <input type="button" value="Show Times Facts" onclick="timestable()" /> </p> <div id="results">Times Facts</div> </form> </body> </html> hey i just started javascript, i have a little syntax question: <HTML> <HEAD> <script type="text/javascript"> function ifPrime(input) { thesqrt = Math.sqrt(input) for(a = 2; a <= thesqrt; a++) { if(input % a == 0) return false; } return true; } function nthPrime(input) { for(i = 2; i <= input; i++) { if( ifPrime(i) ) { document.write(i); document.write("<br />"); } } } </script> </HEAD> <BODY> Enter how many primes <INPUT TYPE=TEXT NAME="userInput" SIZE=6> <INPUT TYPE=BUTTON VALUE="Do it" ONCLICK="value = userInput"> <br /> <br /> <script type="text/javascript"> nthPrime(value) </script> </BODY> </HTML> i would like it post 2 3 5 7 when i type in 10 and press the button. how do I do that? any other programing tips would be appreciated I don't know if this is in the correct section, sorry if it is not. I am creating a form in mailchimp for my site, I need to know if I can put the following all on one line instead of "last name" on one line and "input box" on another line. I know this is probably an easy fix for the pro's! <div class="mc-field-group" style="margin: 1.3em 5%;clear: both;overflow: hidden;"> <label for="mce-LNAME" style="display: block;margin: .3em 0;line-height: 1em;font-weight: bold;">Last Name <strong class="note-required">*</strong> </label> <input type="text" value="" name="LNAME" class="required" id="mce-LNAME" style="margin-right: 1.5em;padding: .2em .3em;width: 95%;float: left;z-index: 999;"> </div> I don't know much about programming but I can't figure out how this works and I want to implement it on my site. I want to copy the code from this page sdapc.com/billing/pay-online.html and implement something similar. I understand that the form uses post and then goes to form-action.php and the information is verified using the script.js, but how is the information sent anywhere. I mean, I don't see any reference to any script that compiles the data and sends it to the billing department. How do they get the info??? Thanks in advance. P.S. If anyone knows of similar scripts or methods out there of doing this I'm all ears (or eyes) This would just be temporary until full automation is developed. For now, I don't mind entering their info into PayPal myself. I am just learning javascript. I am playing around with different html elements and document.write. I have a HTML page with elements h1, h2, h3, and h4. I want to write something (in this example "found it") next to the elements. <head> <script type="text/javascript" language="javascript"> var headerList = getElementsByTagNames('h1,h2,h3,h4'); if (headerList) { document.write("Found it!"); } </script> </head> <body> <h1> </h1> <h2> </h2> <h3> </h3> <h4> </h4> </body> Why doesnt this work? I am assuming my logic is flawed? Hey! Sorry if this is a very remedial question, but I'm trying to make a table, of even and odd numbers organized in two columns (with as many rows as it takes to get through the sequence) and I'm having an issue with my code, obviously - haha. I'm still slightly new.. here is my code Code: document.write('<table>'); for (i=1; i < 50; i++) { document.write("<tr>"); for (j = 0; j < 50; j++) { if (j % 2==0) { document.write('<td>' + j + '</td>'); } else { document.write('<td>' + i + '</td>'); } } } document.write("</tr>); document.write("</table>"); Any help would be greatly appreciated! I'm very very new to javasctipt/html programming and have come upon a stump.Let me explain Code: <form name="for1"> <input type="radio" name="fr1"value="1" > 5 <br> <input type="radio" name="fr1"value="2" > Όσα τα pixels<br> <input type="radio" name="fr1"value="3" > Δεν υπάρχει όριο<br> </form> <input type="button" value="Εκχώρηση Απάντησης" onClick="temp=document.for1.fr1.value"> What i was hoping with this is to store the value of the selected radio in a variable.The variable is declared at the beginning (not shown here).I would appreciate greatly if i'm on the right track to please tell me how to make this work and if possible not create functions and other complicated procedures as it will take me out of my "learning curve".Thanks in advance This is javascript that turns your current url into a tinyurl. How would I go about getting this to open into a new tab instead of the same tab? Code: javascript:void(location.href='http://tinyurl.com/create.php?url='+encodeURIComponent(location.href)) hi guys, l am trying to learn javascript, although certain things seem to be easy to understand, l still have plenty of questions. so l was reading some articles on w3schools and l was an interesting table about operations. http://i1087.photobucket.com/albums/...kesnosense.png if you check above's table you will see at the increment section as well decrement , you will see that in some cases the x and y dont have the same value, now l was just wondering, what is the difference between x=++y and x=y++ ? I know it's possible to do this in php, but what would the javascript equivalent be? Code: var scripts = new Array(); scripts[] = "PHP"; scripts[] = "ASP"; scripts[] = "JavaScript"; scripts[] = "HTML"; But this obviously doesn't work. And just to clarify, I mean the ability to add an array whenever I want to in my page instead of having to name the array like... Code: var scripts = new Array(); scripts[0] = "PHP"; scripts[1] = "ASP"; scripts[2] = "JavaScript"; scripts[3] = "HTML"; I'm using it for such as in a form: Code: <input type="text" name="formarray[]"> <input type="text" name="formarray[]"> Thank you in advance. Hello, I have a script that makes a link a different color on click, i would like to add a hover color to the links that are NOT active. Script below. Thanks in advance! Code: function activate(el) { var links=document.getElementsByTagName("a"); for(i=0;i<links.length;i++) { if(links[i].className=="toggle") { links[i].style.color="#999"; } } el.style.color="#DF8700"; } Any idea why this doesn't work? I'm trying to hide the li with ID of facebook1 if the innerHTML is one of two things. But if both return false and there is more code in there (e.g. a full url), I want to show the li with ID of facebook1 and also add the text 'Facebook Profile' to the span with ID of fbook-add. Code: <ul> <li id="facebook1"><a href="http://facebook.com"><span id="fbook-add"></span></a></li> </ul> <script type="text/javascript"> if(document.getElementById('facebook1').innerHTML.toLowerCase()=='<a href="http://"><span id="fbook-add"></span></a>') { document.getElementById('facebook1').style.display='none'; } else if(document.getElementById('facebook1').innerHTML.toLowerCase()=='<a href=""><span id="fbook-add"></span></a>') { document.getElementById('facebook1').style.display='none'; } else { document.getElementById('fbook-add').innerHTML=='Facebook Profile'; } </script> I am trying to create a javascript program that will assign a number based on a score. If the grade (number) is 90 or above it assigns a 4, if it is in the 80's its assigned a 3, etc. So far: Code: <<?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title> ITS200 Project 6: Quality Points </title> <script type = "text/javascript"> <!-- function QualityPoints() { var form = document.getElementById( "form" ); var input = parseInt( form.number.value); form.points.value = (input >= 0 && input <= 100) Number(input): "Error"; } // end function function Number(grade) { if (grade >= 90) return 4; else if (grade >=80) return 3; else if (grade >=70) return 2; else if (grade >=60) return 1; else return 0; } // end Number function // --> </script> </head> <body> <form id = "form" action = ""> <table border = "1"> <tr> <td> Enter Grade </td> <td> <input name = "number" type = "text" /> </td> <td> <input type = "button" value = "Get Quality Points" onclick = "QualityPoints()" /> </td> </tr> <tr> <td> Quality Points </td> <td> <input type = "text" name = "points" /> </td> </tr> </table> </form> </body> </html> Where do I go from here? I have no idea whats wrong. Hi im trying to make a program that passes an array to a method. the method then finds the smallest number in the array and passes that number back to the main where its printed out. I am getting an error saying: "error: number cannot be resolved to a variable". I am using drjava. here is my code. Code: import java.util.*; public class homeWorkTwo{ public static void main(String[] args) { int[] arrayA; arrayA = new int[10]; arrayA[0]=7; arrayA[1]=5; arrayA[2]=8; arrayA[3]=9; arrayA[4]=2; arrayA[5]=10; arrayA[6]=11; arrayA[7]=1; int lowestNumber = find_sum(number); System.out.print("The smallest number is: "+lowestNumber); } public static int find_sum(int [ ] arrayB){ int isItSmaller=0; int small=0; System.out.println("poop"); for(int i=0;i<=7;i++){ isItSmaller=arrayB[i]; if(small<isItSmaller){} else small=isItSmaller; } System.out.print(small); return small; } } |