JavaScript - Can't Fetch Answers , Json Alert Error
im having issue with fetching answers from database by json file it says error once i click finish button, what do you think the error could be? here is the responses.php file code:
and here is the js code that pulls answers Code: $.ajax({ url :'reponses.php', type : 'POST', data : 'fetchAnswers=' + answerCode + '&id_examens=' + examensId, dataType : 'json', success : function(data){ $(lastButton).html('Finish'); answers =data;// $.parseJSON(data); $(dataDiv).data('answer', answers); callback(answers); }, error : function(resultat, statut, erreur){ $(lastButton).html('Finish'); alert('There was a problem with your network connection. Please click "Finish" again to re-try. If the problem persists, you will have to wait until network connectivity has been restored.'); }, complete : function(resultat, statut){ } }); } else { answers = $(dataDiv).data('answer'); $(lastButton).html('Finish'); callback(answers); } } } when i click the finish button it shows the alert message instead of bring answer and proceed Reply With Quote 01-17-2015, 06:18 PM #2 yamizer View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 2 Thanks 0 Thanked 0 Times in 0 Posts sorry i forgot to add responses.php file codee Code: <?php include("config.php"); header('Content-Type: application/json'); $answers=array(); $sql_questions = 'SELECT * FROM question '; $res_questions = mysql_query($sql_questions); while($data_questions=mysql_fetch_array($res_questions)){ $id_question=$data_questions["id"]; //$sql_answers = "SELECT * FROM reponse WHERE id_question=".$id_question." AND rep_correcte='1'"; $sql_answers = "SELECT * FROM reponse WHERE id_question=".$id_question;//." AND rep_correcte='1'"; $res_answers = mysql_query($sql_answers); $i=1; while($data_answers=mysql_fetch_array($res_answers)){ if($data_answers["rep_correcte"]==1) { $answers[]=$i;//$data_answers['id']; } //$answers[]=$data_answer["rep_correcte"]; $i++; } }//["1","6"] // $answers=array(1,6); echo json_encode($answers); /* $answers=array(1,3,2,1,1,4,1); echo json_encode($answers); */ exit(); ?> Reply With Quote 01-19-2015, 05:44 AM #3 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,311 Thanks 82 Thanked 4,754 Times in 4,716 Posts That is TERRIBLE TERRIBLE PHP coding! (Well, actually SQL coding!) NEVER NEVER do a SELECT *inside* a PHP loop that results from a different SELECT!! But the PHP code makes no sense in any case. You are invoking that page from the JSON code with parameters: Code: 'fetchAnswers=' + answerCode + '&id_examens=' + examensId Yet NOWHERE in the PHP code are you USING those parameters! That is, you should be doing PHP Code: $answerCode = $_POST["answerCode"]; $id_examens = $_POST["id_examens"]; and then USING those values in your PHP code, probably to SELECT the correct records! Similar TutorialsI have an user table like this:- guid | username | password | firstname | lastname | location | emailad dress | userrole -----------------------------------+----------+----------------------------------+-----------+-----------+----------+-------- ------+--------------- 8024259764dc3e8ee0fb6f5.84107784 | james | 827ccb0eea8a706c4c34a16891f84e7b | james | bond | NY | ny@live .com | administrator 18689183644dc3e91571a364.71859328 | saty | 250cf8b51c773f3f8dc8b4be867a9a02 | saty | john | NY | hk@fd.c om | administrator 2644885344cecd6f2973b35.63257615 | admin | 21232f297a57a5a743894a0e4a801fc3 | System | Generated | | | administrator (3 rows) now my postgre query for delete the row .... $query = "delete from users where username!= 'admin' and guid='".$guid."'"; $result = pg_query($conn, $query); ?> <script type="text/javascript"> alert("Cannot delete this .\n It is system generated(s)."); </script> <?php (1)when I delete the user name one by one then delete occurs in my page userlist.php, I donot want to delete admin so i use username!= 'admin' in where condition as shown above. (2)now when I del any username(3 rows) from user table then alert occurs & it delete from userlist.php after that my page userlist.php is blank. Finaly when i refresh the page then my admin username seen.. when i use return true; function then only alert generate .. delete doesnot occurs ... Actauly i want:- (1)if user is not admin then it delete from userlist.php ... nd also i m continue on this page ... like when james and saty want to delte their acount ..as given in table. (2)if user is admin then alert generate nd i m continue on this page. i m tired now plz help me .... so can anyone put the best condition in my coding. I have a very large json file, and inside of that json file is an array. I would like to use JavaScript to take that json as an argument, parse through the json and only take certain elements from it and put it into a new json file, below is an example of what I mean: Code: { "contextType": "Account", "preferences": null, "custodianCode": null, "data": [{ "id": "0", "account": "11111111", "field2": true, "field3": false, "field4": "BROK", "field5": "Broker", "field6": "1", "field7": "Cash" },{ "id": "1", "account": "222222222", "field2": true, "field3": false, "field4": "BROK", "field5": "Broker", "field6": "1", "field7": "Cash" }] } And I want to pull from that and get something like this as a new json Code: { "newArray": [{ "id": "0", "account": "11111111", "field2": true, "field3": false, "field4": "BROK", "field6": "1" },{ "id": "0", "account": "222222222", "field2": true, "field3": false, "field4": "BROK", "field6": "1" }] } Also the file is local to my computer and can be outputted locally as well, I am trying to use node.js and JavaScript this is what I have so far Code: var json = require('./simple.json'); var keeperFields = ["id", "account", "field2", "field3", "field4", "field6"]; var newJSON = {newArray: [] }; var i; var fields; for (i = 0; i < keeperFields.length; i++) { for (fields in json) { if (json.hasOwnProperty(keeperFields[i])) { newJSON.newArray.push(keeperFields[i]); } } } console.log(newJSON); This is just a small example the real json file is huge with thousands of lines. Any help or suggestions are appreciated! This current solution is giving me a console log of { newArray: []} instead of the expected result above Hi everyone-- I am a fourth grade teacher and I have an idea for a program I could use with my students. I think (key word, I don't know anything about programming) that it should be relatively simple to do. A short description of what the program would do will follow, but my posting is for three main reasons: 1) Is this possible? (I assume it is) 2) As I would be willing to pay for this (up to a certain amount), how much might it cost me if I hired a freelance programmer? 3) Is there anyone out there who would be able to help me with this? Okay, as for the program: it would be a program that would make your own "Jack Attack" (like from the computer game "You Don't Know Jack"). It would give you a place to input up to 10 to 15 keywords (or vocabulary definitions) for the middle and keywords (or vocab words) that would fly past. It would respond to some sort of button input (I'm thinking space bar)....and have an action for wrong answers (buzzer sound) and an action for a right answer (ding! and then move on to next question). Maybe after the game it would give a readout of how many right out of how many possible. It would be really cool to be able to have some background music, maybe manipulate the the colors, fonts, etc. I am wanting to leave the program kind of generic so that I could use this for all sorts of applications: use it for vocabulary words in different subjects, match authors with books, "just for fun" games, maybe even use it for some math facts. Any information you would have is more than appreciated! Thanks for helping a teacher out! Clay My code goes through the answer function (below) and it determins if you answered green. If you answered green a popup says correct other wise incorrect. How can I modify my code so that I can add multiple answers for different questions.Example q1 answer = green q2 answer = blue . . q20 answer = Friday Here is my .js code Code: var n = 16; // modify this for number of seconds to answer document.getElementById( 'time').value = "Answer in " + n + " seconds"; var i = setInterval('count()' , 1000); var tooLate; function count() { tooLate = 0; n--; if(n >=0) { document.getElementById( 'time').value = "Answer in " + n + " seconds"; } else { clearInterval(i); alert("Too late!"); if(document.getElementById( 'answer').value == correct){ tooLate = 1; } } function answer() { var correct = "green"; // This is the correct answer if (tooLate == 0) { if(document.getElementById( 'answer').value == correct) { clearInterval(i); alert("Right Answer with " + n + " seconds remaining"); } else{ clearInterval(i); alert("Incorrect! The answer was " + correct); } } submitform(); //submit form function submitform() { document.forms["myform"].submit(); } } Hi I'm Terbinafine I do online school, and it utilizies a popular, virtual education system known as "OdysseyWare". I found a javascript 'cheat' per se, online, which is supposed to reveal the answers to your questions. Here's an example of the source code for a multiple choice question: Code: [EDIT] OdysseyWare Code removed. The code that was removed was a very small javascript piece of code, totaling less than 70 lines. The javascript that was removed here could be recreated by an individual inside of a day, or even 30 minutes or less. It is the Editor’s opinion that, given the ease with which one is able to, apparently, find the answers to the OdysseyWare testing software, the OdysseyWare software is not fit for educational use. What good is testing software that, apparently, allows the user to be able to find all of the answers to the questions by using simple code that they can find on the internet or make themselves? As an educator for many years, I would NOT and will NEVER use this software and cannot recommend that anyone else use it. My code goes through the answer function (below) and it determines if you answered green. If you answered green a popup says correct other wise incorrect. How can I modify my code so that I can add multiple answers for different questions.Example q1.html what color is the grass? q2.htm what color is the sky? . . q20.html what day of the week was the last baseball game? _____________________________________________________ now in my javascript every question is going to go through the answer function and think the answer is green. that would be correct for q1.html but what if i am on q20.html and it goes through the answer function. It will think the answer is green. So how can i change the code so q1.html knows that the answer is green. q2.html knows the answer is blue? here is my code Code: var n = 16; // modify this for number of seconds to answer document.getElementById( 'time').value = "Answer in " + n + " seconds"; var i = setInterval('count()' , 1000); var tooLate; function count() { tooLate = 0; n--; if(n >=0) { document.getElementById( 'time').value = "Answer in " + n + " seconds"; } else { clearInterval(i); alert("Too late!"); document.getElementById('answer').value = ""; tooLate = 1; } } function answer() { var correct = "green"; // This is the correct answer if (tooLate == 0) { if(document.getElementById( 'answer').value == correct) { clearInterval(i); alert("Right Answer with " + n + " seconds remaining"); } else{ clearInterval(i); alert("Incorrect! The answer was " + correct); } } submitform(); //submit form function submitform() { document.forms["myform"].submit(); } } Thank you! Hi, I'm working on a simple website in which I'm required to use two types of forms input on a webpage. I have decided to make a simple quiz which will be designed as follows; -------------------------------------------------------- Q1: The largest mammal on land is: (radio button choices) Q2: Please tick the two correct answers: (tick boxes, four available... only two correct) ---------------------------------------------------------- (BUTTON: Please click here for the answers) ... answers should appear once the above button is pressed... Answers: Q1: B Q2: A * C Is this possible in a simple way? Sounds quite straight-forward but I'm no expert so forgive me.. Ps: Is it possible to design a radio button which, depending on the choice, the related-text will appear underneath on the same page? So if they select 'A' then paragraph 'A' will show, if they select 'C' then paragraph 'C' will appear (with the rest hiding)... Thanks 4 your time! If you type in a question in the question box and select your option and answers from the option and answers box ( do this: open grid, click on button "3", type in "1" in the "Number of Answers" text-box and select button "A" by clicking on it, the button should turn green) Now if you click on the "Add Question" button, it will display a new row in a table which would display the question in the textarea, but how do I code it so that it would display the buttons and the selected buttons under the "Answers" column? The code for inserting a row under the "Answer" column is below: Code: cell = document.createElement("td"); cell.className = "answer"; input = document.createElement("input"); input.name = "answer_" + qnum; cell.appendChild(input); row.appendChild(cell); Whole code is in jsfiddle, click [here][1] [1]: http://jsfiddle.net/mMb8c/21/ I run VLD personals script and would like to show a birthday cake when the time is right for a person. The VLD script outputs the birthday as following: 05 December, 1974 I almost found a sollution by the code below until I realised the years don't match. How can this be resolved? The following code produces: 24 June, 2010 Quote: <script type="text/javascript"><!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]; } var months = new makeArray('January','February','March','April','May', 'June','July','August','September','October','November','December'); var date = new Date(); var day = date.getDate(); var month = date.getMonth() + 1; var yy = date.getYear(); var year = (yy < 1000) ? yy + 1900 : yy; document.write(day + " " + months[month] + ", " + year); //--></script> So if I could find a way to match the day and month with todays, it might be great to have a birthdaycake on a members profile, isn't it? I have this variable from the VLD script and can do as following I guess: Quote: <!-- IF {profile_field_age_value} == "todaysdate" --> show IMG Could anybody help me a bit further? Thx ! :-) I am trying to get a form value on an action page using JavaScript to alert the value. The below doesnt alert anything after I hit the submit button in the one.html page: one.html Code: <form action="two.html" method="get" id="myform"> <input type="text" name="city"> <input type="submit"> two.html Code: <html> <head> <script> alert(document.myform.city.value); </script> </head> <body> </body> </html> Please advise. How to fetch only month from an already existing date text box... eg:05-09-2009(dd-mm-yyyy), i just want to fetch only month(09) in another text box Hi All, Can any one help me in fetching the value from multiselect box. I am writing syntax like this : <select id="status" name="status" multiple="multiple" size='2'> <?php for($i=0; $i<count($status); $i++) { echo "<option value='".$status[$i]['osp_details_id']."'>". $status[$i] ['description']."</option>"; } ?> Now in javascript how can I fetch the values selected by the user. I am trying to Iframe page of some site but I they have blocked, if I try to iframe anygiven page on that site, it would automatically take to the index page of that site. plz show me any other solution thank you Hello, I'm working on a somewhat interactive script that uses dynamic content and I'm quite new to javascript so I was wondering how I could download contents from a source such as a file that would give plain text output, display the output and then the client would wait for X seconds before refreshing the content(Discarding the old content)?
I am creating a customized home page that can display regular links and login forms. I am adding Gmail login form into it. I can further customize it by putting multiple sign in buttons that can fill in username/password for different accounts before submitting. Here's the preview: http://imgur.com/s4Ert.jpg Now the problem is, in Gmail login form a hidden variable called "dsh" is filled with a value that is matched with server as well as a cookie, this value changes in some hours. So this means that I cannot create a complete offline form, but is it possible to load the login page hidden, and catch the value from it? I tried with an iframe with display:none and src="http://mail.google.com" but it opened in the top frame. Any other ideas? In short, what we need is, every time a page is opened from my computer, an online page should be open invisible from the user, and a hidden form value is to be fetched from it. Hi All. I have a dropdown list on a web form containing dates. My Question: How can I call data for that selected item(date) from a MySQL database and display it to the user? And more specifically, if that selected date has no data in the data base, I want to be able to display that as well. I'm looking for a Javascript solution, and if possible a php solution. Thank You! Hi, I am new to javascript, Please help me with the issue below. My javascript code below should actually fetch the data from html table on button click. function displaymessage() { alert ("button pressed"); var table_cells = new Array(); var table7 = document.getElementById('Auth'); for (i=0,n=table7.rows.length; i < n ; i++) { var Rowdata = table7.rows[i]; table_cells[i] = new Array(); for(j=0,cols = Rowdata.cells.length; j < cols; j++) { table_cells[i,j] = Rowdata.cells[j].innerHTML; alert (table_cells[i,j]); } } alert (table_cells[1,1]); alert (table_cells[2,1]); alert (table_cells[3,1]); alert (table_cells[4,1]); alert (table_cells[5,1]); alert (table_cells[6,1]); alert (table_cells[7,1]); alert (table_cells[8,1]); } The problem with my code above is that the statement "alert (table_cells[i,j]);" executes properly and shows the correct value. But the other alert statements shows only the value of the last row of the table. i.e., my table has 9 rows. and all the alert statements shows 9th row's 2nd column's value outside the for loop. But inside the for loop it executes fine. I tried it in IE7. I seem to miss something. Could someone please help me out with this? Thanks in advance. I am trying for a javascript code that would ask for the excel file location when run, fetch data from two columns till eof in an excel file (MS Excel 2010), append it to an existing text file and upload the plain text file to an ftp location. The ftp username, password and location needs to be hard coded in the script. Is this possible? All, I have the following code: Code: <script type="text/javascript"> alert("This picture has received more then 10 down votes so it is now being deleted. You will be redirected back to the pictures page!"); </script> <? echo "<meta http-equiv=\"refresh\" content=\"2;url=http://website.com/pictures.php\">"; ?> This is just in the code. I thought it would just execute this but it doesn't. I can't have it appear on a button event or an onload since this snipped gets executed with AJAX. How can I make it appear? Thanks in advance! I am validating the value in a text area onBlur. If the value is not good the alert box comes up twice. Is there a way to correct this? Code: <html> <head> <meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> <title>Untitled</title> <script type="text/javascript"> function verify_score(val1) { var temp = document.getElementById(val1) if(temp.value == "AF"|| temp.value == "HF" || (temp.value >=0 && temp.value <=17)) {return} else{ alert("Value entered is not OK. Accetable values a 0 to 17, AF or HF") temp.focus() temp.select() } } </script> </head> <body> <div id="PageDiv" style="position:relative; min-height:100%; margin:auto; width:200px"> <form name="scoresheetform" action=""> <div id="Submitbutton" style="position:absolute; left:52px; top:87px; width:110px; height:33px; z-index:1"> <input type=submit name="Submitbutton" value="Submit Form"></div> <div style="position:absolute; left:9.822px; top:37px; width:45px; height:29px; z-index:2"> <input id="HomePlayer1Rnd6Pnts" name="HomePlayer1Rnd6Pnts" onBlur="verify_score('HomePlayer1Rnd6Pnts')" size=3></div> <div style="position:absolute; left:79.822px; top:37px; width:45px; height:29px; z-index:3"> <input id="HomePlayer1Rnd7Pnts" name="HomePlayer1Rnd7Pnts" onBlur="verify_score('HomePlayer1Rnd7Pnts')" size=3></div> <div id="HomePlayer1TotalPnts" style="position:absolute; left:146px; top:37px; width:45px; height:29px; z-index:4"> <input name="HP1 Total Points" size=3></div> </form> </div> </body> </html> |