Jump to content


  • Posts

  • Joined

  • Last visited

About Spunky

  • Birthday 09/29/1989

Previous Fields

  • Languages
    XHTML, CSS, PHP, MYSQL, Javascript, Jquery

Contact Methods

  • Website URL
  • ICQ

Profile Information

  • Gender
  • Location

Recent Profile Visitors

5,351 profile views

Spunky's Achievements


Member (2/7)



  1. Thanks for the reply! I thought I am trying to do a redirect with JavaScript after the AJAX response comes back with the window.location.href line?: xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ retrieve = xmlhttp.responseText; document.getElementById("status").innerHTML = "Thank you!"; window.location.href='https://www.example.com'; } else{ document.getElementById("status").innerHTML = "Uh oh!" } } I figured it was because it doesn't have a chance to get to that line. But then it must have to do with what you said about canceling the form submit event. But, through some research, I am unable to determine what you mean by canceling the form submit event. Why do I want to cancel it?
  2. I have a form that appears in a modal and once the user submits it successfully, the contents get sent to an email. I tried to use JavaScript to redirect but I realize that since there is a post-back, this JavaScript is probably not being hit. I don't even see the Thank You! text that I included. But that's OK, once I can redirect, I can handle a different way to let the user know their form was sent successfully. Looking into redirecting with PHP seemed simple enough but I can't figure out why it is not working for my scenario. Below is my code. The result in Chrome is that all the content that the user filled out in the form end up in the URL such as https://www.example.com/?fname=Test&lname=Test&email=schoell.christine%40gmail.com&phone=&message=testing#openModal - so the modal actually stays open but the form also becomes unusable. IE the result is nearly the same except the modal doesn't appear again. There's two things that I want to accomplish: First, I want to get rid of the stuff in the URL, originally that seemed as simple as redirecting to the same page. But now I'd like to also redirect the user somewhere else. I specify this second thing because I don't just want a solution to remove the text in the URL. Right now, nothing different occurs with the PHP redirect I added. Can someone help me see what I am missing? I'll be honest, I wrote this code years ago so I can't even remember exactly how the text ends up in the URL as I am not savvy in the AJAX being used. If I recall, it has something to do with using the POST method. The only thing new that I have added is the header('Location: https://www.example.com') to the PHP. function validateForm(){ var x = document.forms["contact_form"]["fname"].value; var y = document.forms["contact_form"]["lname"].value; var z = document.forms["contact_form"]["email"].value; //var v = document.forms["contact_form"]["phone"].value; //var k = document.forms["contact_form"]["message"].value; if (x == null || x == "" || y == null || y == "" || z == null || z == "") { return false; } else{ submitForm(); } } $( "form" ).submit(function( event ) { event.preventDefault(); }); function submitForm(){ var xmlhttp = new XMLHttpRequest(); var fn = document.getElementById('fname').value; var ln = document.getElementById('lname').value; var e = document.getElementById('email').value; var p = document.getElementById('phone').value; var m = document.getElementById('message').value; var userdata = "firstname="+fn+"&lastname="+ln+"&email="+e+"&phone="+p+"&message="+m; //var userdata = "firstname=Christine&lastname=Schoell&email=email@email.com&phone=123&message=hi" xmlhttp.open("POST","submit_form.php",true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ retrieve = xmlhttp.responseText; document.getElementById("status").innerHTML = "Thank you!"; window.location.href='https://www.example.com'; } else{ document.getElementById("status").innerHTML = "Uh oh!" } } xmlhttp.send(userdata); document.getElementById("status").innerHTML = "processing..."; return false; } <?php $ToEmail = 'example@example.com'; $EmailSubject = 'Site contact form'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; $MESSAGE_BODY = "First Name: ".$_POST["firstname"]."Last Name: ".$_POST["lastname"].""; $MESSAGE_BODY .= "Phone: ".$_POST["phone"].""; $MESSAGE_BODY .= "Email: ".$_POST["email"].""; $MESSAGE_BODY .= "Comment: ".nl2br($_POST["message"]).""; @mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); header('Location: https://www.example.com'); ?>
  3. Spunky

    Using CSS Selectors

    If only the code in the JSFiddle was a copy-paste of my exact code. But alas, it is not: At best I would have avoided my last response, avoiding yours as well. However, I am doing my best to replicate the HTML markup that I am using in here to figure out what exactly is the problem here. Clearly it is still something else. I will see what structure I am missing from my actual code and see if I can figure this out.
  4. Spunky

    Using CSS Selectors

    I don't see it. I Suppose if I did notice it, I wouldn't be here. 🤔 Are you referring to the YesNo_radio class? Malformed as in a typo?
  5. Spunky

    Using CSS Selectors

    More specifically, the CSS may even be targeting the first instance of .formContainer as well. I've updated the code for another page where table.YesNo_radio doesn't appear in the first .formContainer and none of them are being targeted. Here is a JSFiddle of the example I provided above though: https://jsfiddle.net/juanL52z/4/ Notice how the 2nd instance of the 2nd <span> does not receive the CSS. That's the problem.
  6. Spunky

    Using CSS Selectors

    I'm trying to use CSS selectors to target specific elements throughout my page and I can't figure out proper use to target everything I am trying to. Here my HTML, trimmed for simplicity (I hope): <div id="formWrap"> <div class="formContainer"> <div class="row"> <div class="column"> content </div> <div class="column"> content </div> </div> <!-- more rows --> <div class="row"> <div class="column"> content </div> <div class="column"> <table class="YesNo_radio"> <tbody> <tr> <td> <span> content </span> </td> <td> <span> content </span> </td> </tr> </tbody> </table> </div> <!-- column --> </div> <!-- row --> <div class="row"> <div class="column"> content </div> <div class="column"> <table> <tbody> <tr> <td> <span> content </span> </td> <td> <span> content </span> </td> <td> content </td> </tr> </tbody> </table> </div> <!-- column --> </div> <!-- row --> <!-- more rows, possibly with more tables --> </div> <!-- formContainer --> <div formContainer> <!-- more rows, some with tables --> </div> <!-- more formContainers, with rows, with tables --> </div> <!-- formWrap --> Here is my CSS: #formWrap .formContainer .column table.YesNo_radio td:nth-of-type(2) span{ margin-left:15px; } So basically the HTML is wrappers around rows and columns that I use to layout the content. Trickled in are tables and some of those tables use a special class that need to be treated different: specifically I want the <span> to be treated differently. For every table.YesNo_radio I need the 2nd span to have margin-left:15px;. However, using the CSS shown, it only targets the first .table.YesNo_radio's <span>. I've tried other variations to the CSS such as being even more specific (by including the <tbody>, <tr>), less specific. I think at first I had the selector elsewhere but I feel like I've determined that logically, being on the <td> makes the most sense. CSS selectors can be very complex, so I'm guessing this is just a matter of creating it just right and I just can't figure out the magic combination. I'm hoping someone could help me out in figuring out how to position the selector/which selector to use.
  7. So, I am trying to set up what I am calling a "Guided Tour" which uses CSS tooltips/popups to explain various parts of the page that they are on. I want the "tour" to run automatically, but also give them the ability to pause and continue it at any time, as well as go to the next and previous tip as needed. I'm finding this to be a bit more complex than originally anticipated. Mostly because it seems that using setTimeout() inside a for loop isn't that straight-forward. Let's start with my code: var startG = document.getElementById("startGuide"); var guidetips = []; guidetips[0] = document.getElementById("tip1"); guidetips[1] = document.getElementById("tip2"); guidetips[2] = document.getElementById("tip3"); guidetips[3] = document.getElementById("tip4"); guidetips[4] = document.getElementById("tip5"); guidetips[5] = document.getElementById("tip6"); guidetips[6] = document.getElementById("tip7"); startG.onclick = function(){ guideModal.style.display = "none"; controls.style.display = "block"; runGuideTips(); } function runGuideTips(){ guidetips[0].style.opacity="100"; for(i=0;i<guidetips.length;i++){ if(i === 0){ continue; } setTimeout(toggleTip(i), 3000); } } function toggleTip(i){ return function(){guidetips[i-1].style.opacity="0";guidetips[i+1].style.opacity="100";}; } When the user clicks the button to begin, I have the first tip start out by showing immediately. For that reason, I skip the first iteration. Then, each iteration after I want the prior tip to disappear and the current tip to appear. function toggleTip() was added when I read somewhere that by the time the timeout runs, the for loop is already complete. Their solution was to send the parameter in a function. It does work a little bit better than it was before. What it is doing right now is the first tip shows, then 3 seconds later it disappears and the last tip appears. I get an error in my Console that states: Unable to get property ' style' of undefined or null reference : referring to the function in toggleTip(). The expected result was to go through all 7 guidetips. At the end of the day, I am not certain if I am using the best method to accomplish the end goal that I described. I tried to Google this type of thing because I know I've seen it done before. But I wasn't able to find anything specific on it. So any input or suggestions would be appreciated. :)
  8. The issue I am having is with my menu bar. I have recreated it in JS Fiddle. Notice that when you hover over any of the drop-down menu list items (any that are short words or not on 2 lines), the hover color does not spread to the right edge, and I am unable to figure out why. Could somebody take a look at let me know if they have any ideas?
  9. Real simple here: Why does this work.. tr.retired td:not(:nth-child(2)){ background-color:purple; } And this works... tr.retired td:not(:nth-child(3)){ background-color:purple; } But this doesn't work? tr.retired td:not(:nth-child(2)),tr.retired td:not(:nth-child(3)){ background-color:purple; } Fiddle: https://jsfiddle.net/m6z1suyb/ Thanks!
  10. I prefer MySQLi so I will stick with that, thanks. Easier for me to comprehend as I am not a full fledged programmer. I know all about PDO being more versatile. Sure, ofcourse, my bad, I forget that I can easily run the PHP pages alone without the AJAX triggering it. So, the database connection is working. I ran retrieveData.php by itself and the echo $outp is outputting the data from my database as expected, into a JSON object. The issue now seems to lie solely with the AngularJS now so I'll end this topic as is and move onto a different forum area after I have played with this some more. Thanks for all of your helps. I am glad I finally have a working MySQLi connection to use here,for future projects, and to update older projects. You should test your PHP without AJAX first, or at least check the developer console to see exactly what's being returned in the AJAX request.
  11. They do, says string(#) "content" for each one. Plus the error is showing twice in the same alert box, not sure if that means anything or helps any. How, from my above code, could the $password be empty anyway??? Just to cover my bases from pointing fingers I have also tried: <?php $servername = "localhost"; $username = "username_user"; $password = "password"; $dbname = "username_TableName"; var_dump($servername, $username, $password, $dbname); $db_con = new mysqli('localhost','username_user','password','username_TableName'); if($db_con->connect_error){ die("Connection failed: " . $db_con->connect_error); } ?> (also I realize that where I have TableName is actually database name, I accidentally misinterpreted it as TableName, just don't want to correct it now for consistency) I did just notice, however, that data that I am entering to that the PHP is entering into the database with that connection is actually successfully being added. Hmm... thoughts? Also, I should point out that I am actually connecting to the database as soon as my page loads, before I try to enter data via my form which is actually where I am receiving my error. But I am not getting an SQL error when the page loads, just an AngularJS error which is what I am using with AJAX to communicate. here is the PHP that runs from the start: <?php header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); require 'databaseConnect.php'; $query='SELECT * FROM TaskTracker'; $db_con->query($query); $outp = ""; $result = $db_con->query($query); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { if($outp != ""){$outp .= ",";} $outp .= '{"desc":"' . $row["DESCRIPTION"] . '",'; $outp .= '"id":"' . $row["ID"] . '",'; $outp .= '"status":"' . $row["STATUS"] . '",'; $outp .= '"reminder":"' . $row["REMINDER"] . '",'; $outp .= '"todayDate":"' . $row["DATESTAMP"] . '"}'; } $outp='{"tasks":['.$outp.']}'; } $result->free(); $db_con->close(); echo($outp); ?> The error I am getting is: angular.js:13920 SyntaxError: Unexpected token s in JSON at position 0 Why it is suddenly having an issue with my JSON I do not know. I removed the headers though and that error went away. No error, but data is no longer being fetched from the database to my html page. Here's the AngularJS: $http.get("retrieveData.php").then(function(response){ $scope.tasks = response.data.tasks; }) I've done what I can to convert my code to MySQLi, but I may be missing certain things.
  12. http://stackoverflow.com/questions/30363045/running-php5-access-denied-to-mysqli-connection-but-success-for-mysql Can't say I haven't tried. Maybe you guys would like to take a crack at it then? Because they couldn't help. So let's stay focused on the important part: <?php $servername = "localhost"; $username = "username_user"; $password = "password"; $dbname = "username_TableName"; $db_con = new mysqli($servername,$username,$password,$dbname); if($db_con->connect_error){ die("Connection failed: " . $db_con->connect_error); } ?> The server specific information matches up exactly. All I did was convert it to MySQLi. The error I get: www.mysite.com says: Access denied for user 'username'@localhost (using password: NO) (yes, there is a strangely large gap between the top text and bottom which is right above the OK button.) Any help?
  13. I am unable to connect to my server when I convert the code to MySQLi and I have not been able to figure out why. But I am not too concerned, I only work on small, personal projects. I already discovered what happens when I add an apostrophe to the string which is it doesn't add the item to the database. So I am unsure how that is what is happening here. The code works, it's just now that I am trying to receive $returnData I am getting the error, however the data is still being added to the database. My code was created with the help of w3schools, maybe about 10 years ago, yes. But no need to insult the code, it works, let's focus on the code that isn't working, please.
  14. So I am posting this issue in this part of the forum due to the SQL error that I am getting, so my best guess is there is an error in my SQL. Basically, what I am doing is using angularjs's $https to communicate with a PHP file. Here is that code: $http.post('enterTask.php', task).then( function(response){ alert(response.data); $scope.tasks.push(task); } ); So, I am sending some data which works fine. Where I am getting the error was when I decided I want to receive back data as well and I am using the alert to test the response. Here is the PHP code: <?php $description = $data->desc; $reminder = $data->reminder; $todayDate = $data->todayDate; $status = $data->status; require 'databaseConnect.php'; $query="INSERT INTO TaskTracker (DATESTAMP,STATUS,DESCRIPTION,REMINDER) VALUES ('$todayDate','$status','$description','$reminder')"; mysql_query($query) or die(mysql_error()); $query="SELECT ID FROM TaskTracker WHERE DESCRIPTION = $description"; $result = @mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)){ $returnData = $row["ID"]; } } mysql_close($db_link); echo $returnData; ?> Again, most of this code works just fine, the issue came in when I added everything from the 2nd query and beyond. Here is the error that I am getting when the AJAX runs: You have an error in your SQL syntax: check the manual that corresponds to your MySQL server version for the right syntax to use near 'a 7th test for good luck' at line 1 Part of the data I am sending is here is a 7th test for good luck. And this is stored in $description. Every time this error pops up, it cuts off the first part of it, which I imagine is some clue as to where the error is in the SQL. Any idea? PS: Sorry the PHP code is sloppy, for some reason it appears blank when I post with it in the code box..
  15. 2 typos.. this is what I get for staying up till midnight trying to get this to work... ok so this is what I am getting sent to my email now: Name: [object HTMLParagraphElement]Email: Comment: [object HTMLTextAreaElement] I am not sure why email is still not showing anything. Also I realized I was supposed to add .value to the ends like this: var fn = document.getElementById('fname').value; var ln = document.getElementById('lname').value; var e = document.getElementById('email').value; var p = document.getElementById('phone').value; var m = document.getElementById('message').value; But that didn't do anything. Still, the #1 issue is that the first time I press submit it just reopens the modal the form is in and then it is the second time that it submits. I can try to take it out of the modal and see if that changes anything but either way, I really need it inside the modal. --turns out getting rid of the form fixed this, no need for it I guess anyways since I am not using "onsubmit". EDIT: I am trying to troubleshoot this. When I alert any one of the variables (fn, ln, e, etc) it is undefined and I am not sure why. My JS is located at the bottom of the page before the end body tag so I don't think I need a document ready function but I have tried implementing one which just seems to make it worse. EDIT: Alright this is starting to tick me off.. this is the SIMPLEST JavaScript that I am unable to get to work, I even tried to put it on JsFiddle for a more clear picture and even THAT I can't get to work...https://jsfiddle.net/k1g9dq7w/ -- but anyway this is the code I am currently trying to debug.. simple.. basic.. maybe at this point I should go to the JS forum with this I don't know. ^^^ Ok it seems that if the input is not in a modal, the JS will retrieve the value no problem. I know this is a JS question now, so I am just going to take this to the JS Forums, instead, I have tested this manually by doing: var userdata = "firstname=MyName&lastname=MyLastName&email=email@email.com&phone=123&message=message"; and now this works. So, the code works. I thank you. I will have to figure out my other issue.
  • Create New...