Jump to content

newbe123

Members
  • Posts

    75
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

newbe123's Achievements

Member

Member (2/5)

0

Reputation

  1. My problem is that this only works on Safari and not IE, FF!? <!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=ISO-8859-1" /> <title>JavaScript</title> <link rel="stylesheet" type="text/css" href="stilmall.css" /> <script src="validate.js" type="text/JavaScript"> </script> </head> <body> <h1>JavaScript-sida 2 </h1> <form name="frmInput" method="post" action="mailto:someone@hotmail.com" enctype="text/plain" onsubmit="return validate()"> <p> Name:<br /> <input type="text" name="txtName" size="12" /><br /> Key: (123)<br /> <input type="password" name="txtKey" size="12" /><br /> gender:<br /> <input type="radio" name="radSex" value="Male" />Male<br /> <input type="radio" name="radSex" value="Female" />Female<br /> Ålder:<br /> <select name="selAge"> <option value="">Choose age range</option> <option value="young">0-17</option> <option value="medium">18-64</option> <option value="old">65-</option> </select> <input type="submit" value="OK" /> </p> </form> </body> </html> JavaScript (alert only works on Safari!) function validate() { var returnValue = true; var name = frmInput.txtName.value; var key = frmInput.txtKey.value; var sex0 = frmInput.radSex[0].checked; var sex1 = frmInput.radSex[1].checked; var age = frmInput.selAge.selectedIndex; if (name.length == 0) { alert("Enter name"); // not working frmInput.txtName.focus(); return false; } if (key != "123") { alert("Wrong password!"); //not working frmInput.txtKey.focus(); return false; } if (!sex0 && !sex1) { alert("Enter gender!"); //not working frmInput.txtKey.focus(); return false; } if (age == 0) { alert("Enter age range"); // not working frmInput.txtKey.focus(); return false; } return true; }
  2. Why is this not working? This is what it does: you can type something into the first box, such as your name. Click on the button. This goes through the string one character at a time. .charAt (..) picks up a single character from the string. It then adds it to the front of the output string. This has the effect of reversing it. When you code a loop, you need to know how many times, and in this case it's the number of characters in the string, in other words the string length or xx.length. <HTML> <HEAD> <SCRIPT TYPE="TEXT/JAVASCRIPT"> // Reverse string function reverse() { var inp = document.rev.inpt.value var outp = 0 for (i = 0; i <= inp.length; i++) { outp = inp.charAt (i) + outp } document.reals.outpt.value = outp } </SCRIPT> </HEAD> <BODY> <FORM ACTION="#" NAME="rev"> <INPUT TYPE=TEXT NAME="inpt" SIZE=20 > <INPUT TYPE=BUTTON VALUE="Reverse" ONCLICK="reverse()"><BR> <INPUT TYPE=TEXT NAME="outpt" SIZE=20 DISABLED> </FORM> </BODY> </HTML>
  3. Thank you so much for helping me The part that I did not understand and had problem with was "the idea is that the function to calculate the area to be used inside the function perimeter, so that the perimeter function handles all printing."
  4. this is what I mean <?php if (isset($_POST['calc'])) { $length= $_POST['length']; $width= $_POST['width']; echo "length:" . $length. "<br><br>"; echo "width:" . $width. "<br><br>"; I am not allowed to give the $length = 10; $width = 5; It's like this anyone that going to see this page can give what ever length and what ever width that they want in the text-box and than enters the calculate button and gets the length, the width that he/she gave and the area and the perimeter that was calculated.
  5. Create a method called "perimeter ()" that calculates the perimeter of a rectangle. The function to receive the two parameters "long" and "width" of a form. perimeter shall then be printed on the page when the user presses a button titled "CALCULATE". Create a method called "Area ()" that calculates the area of a rectangle. Call the method "Area ()" method from within "perimeter ()", submit length and width as an argument to the method "Area ()" and use these to calculate the area. Modify Approach "perimeter () "so that it prints the perimeter and area when the user presses the button "CALCULATE". No printing will be done in Approach "Area () " It's like this that the person that visits this page is going to input any number and that presses the button calculate and than the output is like: length: the number given by the person width: the number given by the person perimeter: answer area: answer
  6. I am not allowed to give the length and the width. and I tried not to give the length and width but it did not work. It's not giving me the area and perimeter
  7. the idea is that the function to calculate the area to be used inside the function perimeter, so that the perimeter function handles all printing. This is what I've done but it's not the same as what I have mentioned above. What Should I do? This is what I want to do Create a method called "Area ()" that calculates the area of a rectangle. Call the method "Area ()" method from within "perimeter ()", submit length and width as an argument to the method "Area ()" and use these to calculate the area. Modify Approach "perimeter () "so that it prints the perimeter and area when the user presses the button "CALCULATE". No printing will be done in Approach "Area () " <body> <h1>PHP-sida 4</h1> <form action="php4.php" method="post"> <p>Längd: <input type="text" name="length" size="20" /></p> <p>Bredd: <input type="text" name="width" size="20" /></p> <p><input type="submit" value="CALCULATE" name="calc" /></p> </form> <?php if (isset($_POST['calc'])) { $length= $_POST['length']; $width= $_POST['width']; echo "length:" . $length. "<br><br>"; echo "width:" . $width. "<br><br>"; function perimeter($length, $width) { return 2* ($length+ $width); } $perimeter= perimeter($length, $width); echo "perimeter:" . $perimeter. "<br>", "<br>"; function area($length, $width) { return $length* $width; } $area = area($length, $width); echo "area:" . $area ; } ?> </body>
  8. can someone please help me with this? Please
  9. I really appreciate your help but I wonder if you could take a look at the codes below and see if my comments are right and what I've missed perhaps? Thank u so much function fetchDelicious(json) { var html = ""; / / Create variable html / / Go through all the links json pick up and populate the list for (var i = 0; i < json.length; i++) { var uri = json[i].u; var description = json[i].d; var tags = json[i].t; //array var time = json[i].dt; var author = json[i].a; / / (li do not seem to be used to create 'html', removed) var bHtml = "<li><a href=\":u\"></a>:t</li>".replace(":u", uri).replace("", description); / / Li tags with links placed in the variable bHtml var tagHtml = ""; / / TagHtml harboring tags / bookmarks for each link / / Go through all the tags / bookmarks, and populate the level-two-list for(var n = 0; n < tags.length; n++) { tagHtml += "<li><a href=\"http://delicious.com/:u\"></a></li>".replace(":u", [author,tags[n]].join("/")).replace("", tags[n]); } tagHtml = "<ul>" + tagHtml + "</ul>"; html += bHtml.replace(":t", tagHtml); / / List is created with the li-tags that contain new ul-list of tags / bookmarks } html = "<ul>" + html + "</ul>"; document.getElementById(config.deliciousTarget).innerHTML = html; }
  10. This is how I understand the codes, do not know if I am right or not? Can someone help me and see if my comments are right? function fetchDelicious(json) { var html = ""; / / Create variable html / / Go through all the links json pick up and populate the list for (var i = 0; i < json.length; i++) { var uri = json[i].u; var description = json[i].d; var tags = json[i].t; //array var time = json[i].dt; var author = json[i].a; / / (li do not seem to be used to create 'html', removed) var bHtml = "<li><a href=\":u\"></a>:t</li>".replace(":u", uri).replace("", description); / / Li tags with links placed in the variable bHtml var tagHtml = ""; / / TagHtml harboring tags / bookmarks for each link / / Go through all the tags / bookmarks, and populate the level-two-list for(var n = 0; n < tags.length; n++) { tagHtml += "<li><a href=\"http://delicious.com/:u\"></a></li>".replace(":u", [author,tags[n]].join("/")).replace("", tags[n]); } tagHtml = "<ul>" + tagHtml + "</ul>"; html += bHtml.replace(":t", tagHtml); / / List is created with the li-tags that contain new ul-list of tags / bookmarks } html = "<ul>" + html + "</ul>"; document.getElementById(config.deliciousTarget).innerHTML = html; }
  11. It is this last bit that I would like some help with. I really appreciate if someone could help me and write some comments for these codes. I would really help function fetchDelicious(json) { var html = ""; for (var i = 0; i < json.length; i++) { var uri = json[i].u; var description = json[i].d; var tags = json[i].t; //array var time = json[i].dt; //var n = json[i].n; //new? var author = json[i].a; var bHtml = "<li><a href=\":u\"></a>:t</li>".replace(":u", uri).replace("", description); var tagHtml = ""; for(var n = 0; n < tags.length; n++) { tagHtml += "<li><a href=\"http://delicious.com/:u\"></a></li>".replace(":u", [author,tags[n]].join("/")).replace("", tags[n]); } tagHtml = "<ul>" + tagHtml + "</ul>"; html += bHtml.replace(":t", tagHtml); } html = "<ul>" + html + "</ul>"; document.getElementById(config.deliciousTarget).innerHTML = html; }
  12. I'm totally new when it comes to JavaScript and I'm trying to learn new things. Here I found the codes I tried it and it works but I would like to have comments for the code to understand how they have proceeded. can someone help me and explain these codes with comments? I really appreciate it. var config = { "tags": "vfx+compositing", "user": "andreasl", "scriptTagTarget": "scriptTagDiv", "deliciousTarget": "deliciousLinks", "callbackFunction": "fetchDelicious" }; window.onload = function() { var url = 'http://feeds.delicious.com/v2/json/' + config.user + '/' + config.tags + '?callback=' + config.callbackFunction; var scriptDiv = document.getElementById(config.scriptTagTarget); addScriptTag(url, scriptDiv); }; function addScriptTag(url, scriptDiv) { if (scriptDiv.hasChildNodes()) { scriptDiv.removeChild(scriptDiv.firstChild) }; var scriptElement = document.createElement('script'); scriptElement.setAttribute('src', url); scriptDiv.appendChild(scriptElement); } function fetchDelicious(json) { var html = ""; for (var i = 0; i < json.length; i++) { var uri = json[i].u; var description = json[i].d; var tags = json[i].t; //array var time = json[i].dt; //var n = json[i].n; //new? var author = json[i].a; var bHtml = "<li><a href=\":u\"></a>:t</li>".replace(":u", uri).replace("", description); var tagHtml = ""; for(var n = 0; n < tags.length; n++) { tagHtml += "<li><a href=\"http://delicious.com/:u\"></a></li>".replace(":u", [author,tags[n]].join("/")).replace("", tags[n]); } tagHtml = "<ul>" + tagHtml + "</ul>"; html += bHtml.replace(":t", tagHtml); } html = "<ul>" + html + "</ul>"; document.getElementById(config.deliciousTarget).innerHTML = html; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.