Jump to content

simpli

Members
  • Posts

    165
  • Joined

  • Last visited

    Never

Everything posted by simpli

  1. hi I have an ordered list of 10 input boxes that are one below the other and I would like to have them 5 on a line instead. How would you suggest I go about this? Thanks, J-R
  2. Hi, and thank you for your help. I ran the code you changed but it still doesn't work. I tried to see what change you brought to it and I couldn't see any except that you change value for values. There was a typo where you had replaced value with svalues but I corrected it. Can you tell me what other change you've done if any. Maybe by teaming up we can get it to work. Thanks again, J-R
  3. I don't understand your question. Can you expand? Thank you. J-R
  4. sorry I forgot to paste the code: <script type='text/javascript'> function array_count_values( array ) { // http://kevin.vanzonneveld.net // + original by: Ates Goral (http://magnetiq.com) // + namespaced by: Michael White (http://getsprink.com) // + input by: sankai // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: array_count_values([ 3, 5, 3, "foo", "bar", "foo" ]); // * returns 1: {3:2, 5:1, "foo":2, "bar":1} // * example 2: array_count_values({ p1: 3, p2: 5, p3: 3, p4: "foo", p5: "bar", p6: "foo" }); // * returns 2: {3:2, 5:1, "foo":2, "bar":1} // * example 3: array_count_values([ true, 4.2, 42, "fubar" ]); // * returns 3: {42:1, "fubar":1} var tmp_arr = {}, key = '', t = ''; var __getType = function(obj) { // Objects are php associative arrays. var t = typeof obj; t = t.toLowerCase(); if (t == "object") { t = "array"; } return t; } var __countValue = function (value) { switch (typeof(value)) { case "number": if (Math.floor(value) != value) { return; } case "string": if (value in this) { ++this[value]; } else { this[value] = 1; } } }; t = __getType(array); if (t == 'array') { for ( key in array ) { __countValue.call(tmp_arr, array[key]); } } return tmp_arr; } function formValidator(){ var tmpArray= []; tmpArray = array_count_values([ 3, 5, 3, "foo", "bar", "foo" ]); document.write(tmpArray[0] + tmpArray[1]+ tmpArray[2]); document.write(tmpArray[3] + tmpArray[4]+ tmpArray[5]); // document.write(tmpArray[0] + " " + tmpArray[1]+ " " + tmpArray[2] + " " + tmpArray[3]+ " " + tmpArray[4]+ " " + tmpArray[5]); } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b> </br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player_1" id="player_1" type="text" size="30"></br> <b><label for="player_2" style="width:2em">2</label></b><input name="player_2" id="player_2" type="text" size="30"></br> <b><label for="player_3" style="width:2em">3</label></b><input name="player_3" id="player_3" type="text" size="30"></br> <b><label for="player_4" style="width:2em">4</label></b><input name="player_4" id="player_4" type="text" size="30"></br> <b><label for="player_5" style="width:2em">5</label></b><input name="player_5" id="player_5" type="text" size="30"></br> <b><label for="player_6" style="width:2em">6</label></b><input name="player_6" id="player_6" type="text" size="30"></br> <input type="submit" name="submit" value="Soumettre vos choix"> </form> </br> </body></html>
  5. Hi, I downloaded this javascript that is supposed to be the equivalent of php's array_count_values function but it doesn't seem to be working. While I posted on the website I downloaded it from I don't know how responsive they are. I am on a mac using firefox so I don't know if that's the problem. I am using one of their example to showcase the function. Have anyone used that function on a mac/firefox? (http://phpjs.org/functions/view/308) Can anyone try it on their side to see if it works as it should? If not can anyone help me troubleshoot it? I wanted to find a solution to equal the php function and be quick on my way but I'm stuck trying to debug this. Thanks in advance, J-R
  6. Hi, I've been struggling with assigning data that comes from input textboxes to an array. Very simply, I have six input boxes that I put data in and I want to retrieve then upon submit for treatment. This doesn't seem to be working as I get a msgbox with 'object HTMLInputElement]'. I don't really know what the problem is as I have no error messages from the console and no real way to troubleshoot what's going on. Thanks for any help in advancing this, J-R <script type='text/javascript'> function formValidator(){ // Make quick references to our fields var p1 = document.frmchoixronde1.player_1; var p2 = document.frmchoixronde1.player_2; var p3 = document.frmchoixronde1.player_3; var p4 = document.frmchoixronde1.player_4; var p5 = document.frmchoixronde1.player_5; var p6 = document.frmchoixronde1.player_6; alert(p1); var arrayPlayers = []; arrayPlayers[0] = p1; arrayPlayers[1] = p2; arrayPlayers[2] = p3; arrayPlayers[3] = p4; arrayPlayers[4] = p5; arrayPlayers[5] = p6; alert(arrayPlayers[0]); } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b> </br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player_1" id="player_1" type="text" size="30"></br> <b><label for="player_2" style="width:2em">2</label></b><input name="player_2" id="player_2" type="text" size="30"></br> <b><label for="player_3" style="width:2em">3</label></b><input name="player_3" id="player_3" type="text" size="30"></br> <b><label for="player_4" style="width:2em">4</label></b><input name="player_4" id="player_4" type="text" size="30"></br> <b><label for="player_5" style="width:2em">5</label></b><input name="player_5" id="player_5" type="text" size="30"></br> <b><label for="player_6" style="width:2em">6</label></b><input name="player_6" id="player_6" type="text" size="30"></br> <input type="submit" name="submit" value="Soumettre vos choix"> </form> </br> </body></html>
  7. I don't think the switch is the problem because my alert that is placed much before it doesn't return anything good. I think it's the assignment of the text inputs that is not working for some reason. To verify this I removed the whole function that is bothering you. I'm concentrating on retrieving the information from the textboxes. But it's not working. I can troubleshoot the switch if there's a problem in it but since I have a more pressing issue, I'd like to solve it first. Anyway, thanks for your effort.
  8. I just replaced var tmpArray= new Array(); by var tmpArray= []; and so on everywhere but I still have the same issue
  9. Here's the javascript I copied at jslint function PasDeDoublons( array) { var tmpArray= new Array(); var i = 0; tmpArray = array_count_values(array); for (i=0; i<=tmpArray.length;i++) { if(tmpArray[i] >= 1) { alert("Le joueur ne peut etre choisi deux fois"); return false; } } return true; } function array_count_values( array ) { // http://kevin.vanzonneveld.net // + original by: Ates Goral (http://magnetiq.com) // + namespaced by: Michael White (http://getsprink.com) // + input by: sankai // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: array_count_values([ 3, 5, 3, "foo", "bar", "foo" ]); // * returns 1: {3:2, 5:1, "foo":2, "bar":1} // * example 2: array_count_values({ p1: 3, p2: 5, p3: 3, p4: "foo", p5: "bar", p6: "foo" }); // * returns 2: {3:2, 5:1, "foo":2, "bar":1} // * example 3: array_count_values([ true, 4.2, 42, "fubar" ]); // * returns 3: {42:1, "fubar":1} var tmp_arr = {}, key = '', t = ''; var __getType = function(obj) { // Objects are php associative arrays. var t = typeof obj; t = t.toLowerCase(); if (t == "object") { t = "array"; } return t; } var __countValue = function (value) { switch (typeof(value)) { case "number": if (Math.floor(value) != value) { return; } case "string": if (value in this) { ++this[value]; } else { this[value] = 1; } } }; t = __getType(array); if (t == 'array') { for ( key in array ) { __countValue.call(tmp_arr, array[key]); } } return tmp_arr; } function formValidator(){ // Make quick references to our fields var p1 = document.frmchoixronde1.player_1; var p2 = document.frmchoixronde1.player_2; var p3 = document.frmchoixronde1.player_3; var p4 = document.frmchoixronde1.player_4; var p5 = document.frmchoixronde1.player_5; var p6 = document.frmchoixronde1.player_6; var arrayPlayers = new Array(); arrayPlayers[0] = p1; arrayPlayers[1] = p2; arrayPlayers[2] = p3; arrayPlayers[3] = p4; arrayPlayers[4] = p5; arrayPlayers[5] = p6; alert(arrayPlayers[0]); // Validation of the text fields! if(PasDeDoublons(arrayPlayers)){ return true; } return false; } And here is the first error message I get: Problem at line 3 character 23: Use the array literal notation []. Well that's chinese to me. Even after I googled it I don't see what's wrong with the way I declare my array. That's how it's declared on most tutorial sites. so I'm at a loss. J-R
  10. I don't understand what you mean. What variable am I using as a function. The switch may be screwed up. I didnt get to troubleshoot it. But it's not getting there ok so I need to solve this first. Can you elaborate on your first statement? Thanks, J-R
  11. We are agreed however that the first time I go through the file my form is going to be output (as I show it to the user)? So for it to work I must make sure that in the validation process nothing whatsoever is returned to the user before I use the header function is this correct? J-R
  12. Hi, I am having problems with the header function. I think I dont understand it and I'm stepping back a little to see if I can learn it better. Here is my situation: I have a form that calls itself back when the submit is pressed. After the data is validated and I have written on the database I want to go to another page and that's where it doesnt work. Now I know one thing: If I have output anything to the web page I know that header will not work. My question is this: Since the form calls itself back does that mean the header function will inherently not work in this situation? Can you propose me an alternative or a workaround? Thank you, J-R
  13. Hi, I downladed a js script that is supposed to replicate the array_count_values php function. It's my first time using arrays in php and I am stuck. I don't seem to be getting the data in the array. Obviously the array_count_values doesnt work but I think it's my implementation of arrays that doesnt work. I tried running the script I have no error in my browser so I don't know where to look now. Can anyone troubleshoot me? Thanks <script type='text/javascript'> function formValidator(){ // Make quick references to our fields var p1 = document.frmchoixronde1.player_1; var p2 = document.frmchoixronde1.player_2; var p3 = document.frmchoixronde1.player_3; var p4 = document.frmchoixronde1.player_4; var p5 = document.frmchoixronde1.player_5; var p6 = document.frmchoixronde1.player_6; var arrayPlayers = new Array(); arrayPlayers[0] = p1; arrayPlayers[1] = p2; arrayPlayers[2] = p3; arrayPlayers[3] = p4; arrayPlayers[4] = p5; arrayPlayers[5] = p6; alert(arrayPlayers[0]); // Validation of the text fields! if(PasDeDoublons(arrayPlayers)){ return true; } return false; } function PasDeDoublons( array) { var tmpArray= new Array(); var i = 0; tmpArray = array_count_values(array); for (i=0; i<=tmpArray.length;i++) { if(tmpArray[i] >= 1) { alert("Le joueur ne peut etre choisi deux fois"); return false; } } return true; } function array_count_values( array ) { // http://kevin.vanzonneveld.net // + original by: Ates Goral (http://magnetiq.com) // + namespaced by: Michael White (http://getsprink.com) // + input by: sankai // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: array_count_values([ 3, 5, 3, "foo", "bar", "foo" ]); // * returns 1: {3:2, 5:1, "foo":2, "bar":1} // * example 2: array_count_values({ p1: 3, p2: 5, p3: 3, p4: "foo", p5: "bar", p6: "foo" }); // * returns 2: {3:2, 5:1, "foo":2, "bar":1} // * example 3: array_count_values([ true, 4.2, 42, "fubar" ]); // * returns 3: {42:1, "fubar":1} var tmp_arr = {}, key = '', t = ''; var __getType = function(obj) { // Objects are php associative arrays. var t = typeof obj; t = t.toLowerCase(); if (t == "object") { t = "array"; } return t; } var __countValue = function (value) { switch (typeof(value)) { case "number": if (Math.floor(value) != value) { return; } case "string": if (value in this) { ++this[value]; } else { this[value] = 1; } } }; t = __getType(array); if (t == 'array') { for ( key in array ) { __countValue.call(tmp_arr, array[key]); } } return tmp_arr; } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b> </br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player_1" id="player_1" type="text" size="30"></br> <b><label for="player_2" style="width:2em">2</label></b><input name="player_2" id="player_2" type="text" size="30"></br> <b><label for="player_3" style="width:2em">3</label></b><input name="player_3" id="player_3" type="text" size="30"></br> <b><label for="player_4" style="width:2em">4</label></b><input name="player_4" id="player_4" type="text" size="30"></br> <b><label for="player_5" style="width:2em">5</label></b><input name="player_5" id="player_5" type="text" size="30"></br> <b><label for="player_6" style="width:2em">6</label></b><input name="player_6" id="player_6" type="text" size="30"></br> <input type="submit" name="submit" value="Soumettre vos choix"> </form> </br> </body></html>
  14. I have a form that has been validated both on client and server side. Once the data is validated on the server side, the data is written on the database. Currently it stands on the page of the form with all fields blanked out. I find it not very intuitive. What I'd like to do is once the data has been written to the database to go to another page. I tried but header but it's not working. Some people suggested using HTML redirect but that wouldnt solve my problem as the user would be automatically redirected to another page (after a stated delay granted). Thats not what I want. I want the user to enter its information and when that's done correctly and the form has been written to the database I want him to be moved on. What would be the proper approach to do this? Thank you, J-R
  15. Hi, I have a form with let's say 10 input fields Player1='Wayne Gretzky' player2='Mario Lemieux' player3='Wayne Gretzky' and so on until 10. I do NOT want users to choose the same player twice. How could I verify if this rule is respected in php? Is there a ready-made function with arrays which I can count the number of occurence of each single players? Or do i have to go recursively and check that each player hasn't been inserted before? I wouldn't want to do it recursively as I know it would not be efficient. Any input is welcome. Thank you, J-R
  16. If I have already sent something to the page is there another function I can use to redirect the user to another page? I'm not sure I understand the usefulness of this function if we cannot use it after stuff has been output to the web page. If for instance I have a validation form that was created through php and then the form is validated ok and I want to write some data and then send it on to the next page. Technically data has been output to the page (The first time when i created the page). So how would/should I go about doing what I wanna do? Thanks for clarifying. J-R
  17. Hi, I have a form. It was validated, treatment was done data inserted in my db and I want to redirect the user to another page so I use header("http://localhost/showresults.php"); Nothing happens however. In the documentation they say header must be used before anything is output and I'm not sure I understand that. Does that mean that from the moment you have output something in your web page header will not work? Anyhow can someone tell me what I should use to redirect the users to the above page? Thank you, J-R
  18. Hi, I have using phpmyadmin. I created tables but in the course of my programming the design of the tables have changed. Is there a way I can obtain the create table statements that would give me a table structure similar to what I currently have? I want to store these away in the event I have to recreate the tables. Thanks for the help. J-R
  19. Does that mean that if I break the connection I can resume it later just by adding the include? In this sense it would work like a function that is called several times. Why not do a function then? Thanks for clarifying. J-R
  20. Hi all, I have a problem with my connection. As is illustrated in this non working code (I wanted to show what I do for advice not debugging), the first time I connect to the page I connect to the database and retrieve the information to build the form that I want the user to fill. when the user submits, the same page is called but this time is redirected to the server side validation. After the data has been validated, I now want to insert it in the database. I had no luck referring to the connection variables as global and therefore I have to redeclare and reassign the value to them which basically means that I have the connection information at several places in my code. What can I do to remedy that situation. Should I have a connection function that I could call at several places or is there a way i can declare the connection info so it can be accessed from every place and function from my php file? Thanks for your help. J-R <?php //php stuff forms etc //If we get here as a result of the submit button having been pushed: We are going to validate the data if(isset($_POST['submit'])){ //if we came here as a result of submit: Do some validation etc etc.. } //Server side validation ok we write to database or if there's an error we writte error msg if($error == ''){ addmatchups(); }else{ echo '<fieldset class="six" style="width:450px">'; echo '<legend>Erreurs</legend>'; echo $error; echo '</fieldset>'; } } //If we didnt come here as a result of a submit button (1st time form is displayed) // Connects to database $dbhost = 'localhost'; $dbuser = 'xyz'; $dbpass = 'whatever'; $dbname = 'dbwhatever'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> <?php //build the form etc.... } //End of the form ?> </form> </br> </body></html> <?php function addmatchups() { //Some variable declaration etc... //Here I must redeclaremy connection stuff How can I avoid this? $dbhost = 'localhost'; $dbuser = 'xyz'; $dbpass = 'whatever'; $dbname = 'dbwhatever'; $lconn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); //writing in database etc.... } ?>
  21. I dont even know what a doctype is. The only reason i am using absolute is because i understand it and I find it simple. Do you have any suggestion? Why is absolute wrong? Thanks for the advice, J-R
  22. Guys thank you all, I was already on Firefox so i just fired up my console and were able to see my errors. It's much better that way. Most of them were corrected easily with the help of the console. Without the console it was a bit like flying blind. Especially since I was new to js. Thank you all very much. J-R
  23. I'm on a mac and using MAMP. I dont know how to access the error console. Any clue? J-R
  24. Hi, I've been trying to do a validation script for a form with textfields and radiobuttons. I've been having all sorts of problems as witnessed by my many postings. I admit at first I tried to do things too fast by just copy pasting. Since, I did the time to read some docs and further my knowledge. I have also cleaned my code (it was really messy) and decided to do a reboot and start with the field validations. Instead getelementbyid I am now using the document.form.object format. But still no luck. I have a very simple form with one text field that I want to validate. For some reason it doesn't work. I believe the function is called but that it doesnt get my field correctly because the validation doesnt run. Anyone can take a good look and tell me what I am doing wrong? I look at the code and I think it should be working but it's not. <script type='text/javascript'> function formValidator(){ // Make quick references to our fields var p1 = document.frmchoixronde1.player_1; // Validation of the text fields! if(notEmpty(p1, "Votre Joueur #1 n'a pas ete choisi")){ return true; } return false; } function Empty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } function radioSelected(radioGrp) { if (radioGrp.length) { //There are 2 or more options for (var i=0; i<radioGrp.length; i++) { if (radioGrp[i].checked) { return true; } } //No options were checked return false; } else { //There is only 1 option return radioGrp.checked; } } </script> <form id="frmchoixronde1" name="frmchoixronde1" method="POST" enctype="application/x-www-form-urlencoded" onsubmit='return formValidator()'> <html><head><title>Page des poolers</title></head> <body> <b>Entrez vos choix pour la premiere ronde</b><menu class="one">hello jeanru<p></menu> </select></fieldset></br></br><fieldset> <b><label for="player_1" style="width:2em">1</label></b><input name="player_1" id="player_1" type="text" size="30"></br> </fieldset><input type="submit" name="submit" value="Soumettre vos choix"></form> </br> </body></html>
  25. I dont understand the '===' operator. What does it do and why should i use it here.. Also what do you mean when you say to use the code tag? I dont know what it is so if I am being rude please accept appologies. Thank you for explaining etiquette. J-R
×
×
  • 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.