Jump to content

tjmbc

Members
  • Posts

    26
  • Joined

  • Last visited

    Never

Everything posted by tjmbc

  1. I am trying to write a simple function that makes a div change background colors randomly. Here's the code so far: function setBackground() { var digit = new array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'); //Creates an array with hex digits. digit.sort(function() {return 0.5 - Math.random()}); //Randomizes the above array. clr = "+" + digit[0] + digit[1] + digit[2] + digit[3] + digit[4] + digit[5]; //Puts the array in color form (ie. #00ff00). boxdiv.style.backgroundColor = clr; //Sets the background color of the div tag. } The code doesn't work. If I put the line... boxdiv.style.backgroundColor = "#00ff00"; ... it will change the color. (The function is tied to a buttons 'onClick' event). Anyone know what I'm missing?
  2. I am clueless about ajax so bear with me... I know that you have to use a "prototype.js" file to run an ajax script, but does your server have to have something to be 'ajax enabled'?
  3. This is a portion of my code that I am having problems with with the xml page pasted below. The script runs fine when I don't include the height and I can replace height with "width" and it will work. I just can't figure out why the code doesn't work when I try to parse the height. I pasted my full code at the bottom of this post. function getXMLSuccess(originalRequest) { var resultText = ""; var response = originalRequest.responseXML; var heights = response.getElementsByTagName('height'); var widths = response.getElementsByTagName('width'); var bgColors = response.getElementsByTagName('bgcolor'); var borders = response.getElementsByTagName('border'); var height = heights[0].firstChild.nodeValue; var width = widths[0].firstChild.nodeValue; var backColor = bgColors[0].firstChild.nodeValue; var border = borders[0].firstChild.nodeValue; resultText = height + " " + width + " " + backColor + " " + border; createBox(height, width, backColor, border); $('xmlResult').innerHTML = resultText; } //The xml page that is parsed. <mybox> <label> <height>100px</height> <width>300px</width> <bgcolor>#ff0000</bgcolor> <border>1px solid black</border> </label> </mybox> <html> <head> <title>AJAX Midterm</title> <script src="prototype-1.6.0.2.js" type="text/javascript"></script> <script language="JavaScript" type="text/javascript"> var boxdiv; function parseXML() { alert("parseXML Called"); } function getXML() { new Ajax.Request('description.xml', { method:'get', onSuccess: getXMLSuccess, }); } function getXMLSuccess(originalRequest) { var resultText = ""; var response = originalRequest.responseXML; var heights = response.getElementsByTagName('height'); var widths = response.getElementsByTagName('width'); var bgColors = response.getElementsByTagName('bgcolor'); var borders = response.getElementsByTagName('border'); var height = heights[0].firstChild.nodeValue; var width = widths[0].firstChild.nodeValue; var backColor = bgColors[0].firstChild.nodeValue; var border = borders[0].firstChild.nodeValue; resultText = height + " " + width + " " + backColor + " " + border; createBox(height, width, backColor, border); $('xmlResult').innerHTML = resultText; } function createBox(hei,wid,bcolor,brdr) { boxdiv = document.createElement('div'); boxdiv.style.height = hei boxdiv.style.width = wid boxdiv.style.backgroundColor = bcolor boxdiv.style.border = brdr document.body.appendChild(boxdiv); } function addText() { boxdiv.innerHTML = "<h2> My Dynamic Box </h2>"; } </script> </head> <body> <input type=button id="click" value="Click" onClick="getXML();"> <div id="xmlResult"></div> </body> </html>
  4. Is there a query that can count similar occurances. I'm trying to see how many users are registering on my site organized by timestamp. Any ideas?
  5. I would like to display data from my tables organized by date. For instance, I would like to see how many users registered today and yesterday separately. Each new user is marked with a timestamp. How do I do this?
  6. I think I answered my own question... I guess Microsoft is the only browser that recognizes the pjpeg mime type. Anyone know what the point IE was trying to make by changing the jpeg mime type to pjpeg in the first place?
  7. 1) Try: include("public_html/phptest/AbConnect.php"); Instead of: include("/public_html/phptest/AbConnect.php") 2) To go up a dirctory use ../ so if you were in the "phptest" directory and wanted to go up to the "public_html" directory you would type ../newDirectory . if you are down two directories from root and want to go back to root simply type "../../newDirectory". You can put include files anywhere, just make sure you call them with the correct path. Use "require" instead of "include" as a way of testing to see if the included file is found. If you use require, the page won't load at all and you'll know that the page you wanted to include wasn't found.
  8. I use the below code to make sure that users are using the proper format to upload pictures. Some users try to upload jpeg's and still get error's saying that their file is the wrong type. What am I missing? if (!($userfile_type == "image/pjpeg" || $userfile_type == "image/gif")) { header("Location: http://www.connectingcadence.com/process/error.php?addimgck=type"); exit; }
  9. I am using the mail() function to send an activation email to users upon registration, but hotmail keeps throwing these messages into a junk mail folder automatically. Is there a php work around for this?
  10. I've been using a single dynamic page to show content and I would prefer to use a separate page. For instance: A user submits a form with their name. Rather than displaying the name in say, the title dynamically: <title><? echo $user['name']; ?><title> I would like a new page like this: <title>John Doe</title> Can php do this?
  11. That worked perfect, but forgive me for saying I'm not sure how to replace the original table with the 'tmp' one. Anyone?
  12. How do I delete duplicate records that have unique keys? For instance, in my table there is: id | value1 | value2 | value3 1 a b c 2 a b c I want to delete record 2 (or 1). I suppose I should also mention that there are a few thousand records in the table.
  13. Use strip_tags() with exceptions. strip_tags( $_POST['variable'], '<p>' ) This will allow the user to use the <p> tag. Replace the <p> with whatever tag you don't want stripped or allow multiple tags with '<p>,<a>'. You should also notice that you don't have to include the closing tag in the exception.
  14. i have an array that I used explode() on to break it up into variables i can echo each variable by calling it with $variable[0] then $variable[1] but how do I print all of the variables without calling each one individually? i'm guessing its something like while(???some sort of code to that i don't know???) { echo $variable; }
  15. How do I make it so my page is only shown after it has been completely loaded rather than it being pieced together.
  16. anyone know how I can put line breaks in a string every time there is a digit. i have a mysql text field that has a string like this: 3/4 went to the store 12/4 went to the store 8/16 had a popsickle i want to take that string and make it like this: 3/4 went to the store 12/4 went to the store 8/16 had a popsickle any idea's?
  17. I need to check to see if this is a whole number... $num_in / 5
  18. $first_friend = "Bobby"; $relationship = " is friends with "; $first_half_of_string = "Ricky"; $second_half_of_string = " who".$relationship.$first_friend; Returns: who is friends with Bobby $full_string = $first_half_of_string.$second_half_of_string; Returns: Ricky who Why is the full string "Ricky who is friends with Bobby" not returned? The string stops at who...?
  19. Thank you. You were right, my ordering of statments was wrong. So I don't run accross this again, I stopped messing with 'php_self' processing my forms and just made a seperate form processing page for my site. This solved the problems for all of my pages. I think for us beginners this is the way to go.
  20. <?php //If user is already logged in, show welcome message and logout option. if (isset($_SESSION['Username'])){ echo "Welcome back ".$_SESSION['fname']."!<br />"; echo "<a href='http://www.domain.com/index.php?sign_out=yes'>Sign out.</a>"; } else{ echo "<form id='form1' name='form1' method='POST' action='$_SERVER['PHP_SELF'];'><label> Email:<br /> <input type='text' name='email' id='email' /> Password:<br /> <input type='password' name='password' id='password' /><br /> <div align='right'> <input type='submit' name='button' id='button' value='Submit' /> </div></label></form>"; } ?>
  21. **warning: newbie thoughts exist beyond this point** I have a logout link that destroys a session: if (isset($_SESSION['Username'])){ echo "Welcome back ".$_SESSION['fname']."!"; echo "<a href='http://www.domain.com/index.php?sign_out=yes'>Sign out.</a>"; } else{ echo (A sign in form.); } That statement gets processed on the same page with this: if (isset($_GET['sign_out'])){ session_destroy(); } After the link is clicked and the session is destroyed, the link to 'sign out' still appears on the page. When I click it again, it then displays the 'sign IN' form that it's supposed to. So basically, I have to click the 'sign out' link twice to get it to disappear and show the 'sign in' form. All of my links seem to do the same thing. For instance, I have a link that, when clicked, deletes a row from mysql. I have to click the link twice to make the link not appear on my page, but I know from querying the database after the first click that the row was deleted already. Any help would be appreciated. Even if you could just tell me what it's called that I'm doing wrong so I can find some tutorials or something.
  22. Here's my code so far: $query = "SELECT COUNT(*) FROM table"; $result = mysql_query($query); How do I display the result on my page?
  23. Can I use this function: function mysqldb(){ $host = "host"; $user = "user"; $password = "password"; $database = "database"; mysql_connect($host,$user,$password) or die ("Unable to connect to the server."); mysql_select_db($database) or die ("Unable to connect to the database."); } to connect to my database by including it in each page and then calling it with: mysqldb(); I know that this is something I should just try out and see what happens, but I can't at this time. Long story...
  24. Here's the value function in the form class: function value($field){ if(array_key_exists($field,$this->values)){ return htmlspecialchars(stripslashes($this->values[$field])); }else{ return ""; } }
  25. Here's the form that I'm using... <form action="../login/process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr> <td>Current Password:</td> <td><input type="password" name="curpass" maxlength="30" value=" <?echo $form->value("curpass"); ?>"></td> <td><? echo $form->error("curpass"); ?></td> </tr> <tr> <td>New Password:</td> <td><input type="password" name="newpass" maxlength="30" value=" <? echo $form->value("newpass"); ?>"></td> <td><? echo $form->error("newpass"); ?></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" maxlength="50" value=" <? if($form->value("email") == ""){ echo $session->userinfo['email']; }else{ echo $form->value("email"); } ?>"> </td> <td><? echo $form->error("email"); ?></td> </tr> <tr><td colspan="2" align="right"> <input type="hidden" name="subedit" value="1"> <input type="submit" value="Edit Account"></td></tr> <tr><td colspan="2" align="left"></td></tr> </table> </form>
×
×
  • 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.