JavaScript - Jquery Poll Not Posting To Database
delete this
Similar TutorialsHello, I am new to this forum and hope this is in the right place but I have been trying to code (with no success) a voting system with PHP/MySql and jQuery for a clients webpage and am about to throw my computer out the window. Any help/advice would be appreciated, heres my dilemma. I need to create a simple system where a viewer can vote (only one vote) between two options (only 2). Example: [heading]Do you brush your teeth [radio button]Option 1: Yes [radio button]Option 2: no [submit] upon submission jQuery would then show the results without leaving the page. there is also 16 things to vote on per page (i dont know if this changes anything) Thanks in advance, J Hello All, Forgive me if my terminology is off, as I am a Java and PHP newbie, but i will do my best to explain my problems. I am building a simple site for my job and the HTML and CSS is done. I used a simple PHP script to post form data to an SQL table. I wanted to first create a client side form validator to ensure proper data was being entered into the form (First name, last name, phone, email, state, zip code). Data was being posted to the form no problem prior to the Javascript validation. Now that the Javascript validation is in place, no data is passed to the database and only empty records appear in the table when the form is submitted. How do I get Javascript and PHP to play nicely together? I still need to create a server side validation and also a sanitation script to make sure no one tries to inject malicious code, but my main focus now is making sure data can get posted to the database. Please help me out, and correct any incorrect terminology I'm using. This is my form: Code: <form name="form1" id="form1" "method="post" action="insert.php"> <table width="80%" border="0"> <tr> <td align="right">First Name : </td> <td><input type="text" name="fname" style="width:170px;"></td> </tr> <tr> <td align="right">Last Name : </td> <td><input type="text" name="lname" style="width:170px;"></td> </tr> <tr> <td align="right">Phone : </td> <td class=><input type="text" name="phone" style="width:100px;"> </td> </tr> <tr> <td align="right">Email : </td> <td> <input type="text" name="email" style="width:170px;"></td> </tr> <tr> <td align="right">State : </td> <td><select name="state" style="width:150px;"> <option value="000" selected="selected">Select</option> <option value="Alabama">Alabama</option> <option value="Alaska" >Alaska</option> <option value="Arizona" >Arizona</option> <option value="Arkansas" >Arkansas</option> <option value="California" >California</option> <option value="Colorado" >Colorado</option> <option value="Connecticut" >Connecticut</option> <option value="Delaware" >Delaware</option> <option value="District-of-Columbia" >District of Columbia</option> <option value="Florida">Florida</option> <option value="Georgia" >Georgia</option> <option value="Hawaii" >Hawaii</option> <option value="Idaho" >Idaho</option> <option value="Illinois" >Illinois</option> <option value="Indiana" >Indiana</option> <option value="Iowa" >Iowa</option> <option value="Kansas" >Kansas</option> <option value="Kentucky" >Kentucky</option> <option value="Louisiana" >Louisiana</option> <option value="Maine" >Maine</option> <option value="Maryland" >Maryland</option> <option value="Massachusetts" >Massachusetts</option> <option value="Michigan" >Michigan</option> <option value="Minnesota" >Minnesota</option> <option value="Mississippi" >Mississippi</option> <option value="Missouri" >Missouri</option> <option value="Montana" >Montana</option> <option value="Nebraska" >Nebraska</option> <option value="Nevada" >Nevada</option> <option value="New-Hampshire" >New Hampshire</option> <option value="New-Jersey" >New Jersey</option> <option value="New-Mexico" >New Mexico</option> <option value="New-York" >New York</option> <option value="North-Carolina" >North Carolina</option> <option value="North-Dakota" >North Dakota</option> <option value="Ohio" >Ohio</option> <option value="Oklahoma" >Oklahoma</option> <option value="Oregon" >Oregon</option> <option value="Pennsylvania" >Pennsylvania</option> <option value="Rhode-Island" >Rhode Island</option> <option value="South-Carolina" >South Carolina</option> <option value="South-Dakota" >South Dakota</option> <option value="Tennessee" >Tennessee</option> <option value="Texas" >Texas</option> <option value="Utah" >Utah</option> <option value="Vermont" >Vermont</option> <option value="Virginia" >Virginia</option> <option value="Washington" >Washington</option> <option value="West-Virginia" >West Virginia</option> <option value="Wisconsin" >Wisconsin</option> <option value="Wyoming" >Wyoming</option> </select> </td> </tr><tr> <td align="right">Zip Code: </td> <td><input type="text" name="zcode" style="width:50px;"></td> </tr> <tr> <td> </td> <input type="hidden" name="submitted" value="1"> <td><input type="submit" value="Submit" name="submit"></td> </tr> </table> </form> This is my javascript code that links to an external .js file: Code: <script type="text/javascript"> var frmvalidator = new Validator("form1"); frmvalidator.addValidation("fname","req","Please enter your First Name"); frmvalidator.addValidation("fname","minlen=2","Minimum length for First Name is 2 characters"); frmvalidator.addValidation("fname","maxlen=20","Max length for First Name is 20 characters"); frmvalidator.addValidation("lname","req","Please enter your Last Name"); frmvalidator.addValidation("lname","minlen=2","Minimum length for Last Name is 2 characters"); frmvalidator.addValidation("lname","maxlen=20","Max length for Last Name is 20 characters"); frmvalidator.addValidation("email","req","Please enter a Valid Email Address"); frmvalidator.addValidation("email","maxlen=50"); frmvalidator.addValidation("phone","req","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","minlen=10","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","maxlen=10","Please enter your 10-digit Phone Number. Example: 5051234567"); frmvalidator.addValidation("phone","numeric"); frmvalidator.addValidation("state","dontselect=000","Please select your state"); frmvalidator.addValidation("zcode","req","Please enter your 5-digit Zip Code"); frmvalidator.addValidation("zcode","minlen=5","Please enter your 5-digit Zip Code"); frmvalidator.addValidation("zcode","maxlen=5","Please enter your 5-digit Zip Code"); </script> This is my insert.php file that form uses: PHP Code: <?php $con = mysql_connect("localhost","**********","**********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sms2011_leads", $con); $sql="INSERT INTO sms2011_prospects (fname, lname, phone, email, state, zcode) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[phone]','$_POST[email]','$_POST[state]','$_POST[zcode]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<script>window.location = 'http://www.nationalcollegesearch.org/thankyou.html';</script>"; mysql_close($con) ?> Hi all, I need poll system only in javascript and xml/text file. example: What is your age ? option: 10 option: 20 option: 30 option: 40 Button Vote and Result show result in same div in Bar Please help its urgent. Hi everybody. I need some help too build a poll with 2 answer option people can select and 5 rating stars . something like this 1. Yes you're bad (344567)| 2.No you're good (5676)| Here 5 stars they can rate. the numbers stand for how much people clicked on that option But it is a blog with wordpress system . But every story need there own poll. And i m not a expert in xml or what other system i need to build this . Can somebody help me. Thank you. Sorry for my poor english hi there i need your help. i would like to build a small poll. client should receive the data from server (a JSON file). client will load the data. It'll send the selection to the server, after the user has acted. The poll should look like this. **** are you a linux user? Yes No **** Yes and No with radio buttons. So the end result should look like this..If i open a website, the page will be dynamically created and it'll load the data ("are you a linux user?") from the server. The selection will be sent to the server where this saves the selection. Hope someone could help me out with this? So, i have this code which retrieves php files for me using jquery and id love to get it working with Jquery history plugin. I tried modifying the code i got from the ajax demo to work for me, but i just couldnt do it as i do not know any javascript really.. ( actually what i tried was simply to change "#ajax-links a" to "#menu li a" and .html to .php ..but nothing.. :rolleyes: Id be very gratefull if someone would help me out with this one. All related code can be found bellow (the ones that should be needed anyways): This is the code that retrieves php files inside "#content" when item from "#menu li a" with the specified id is clicked Code: $(document).ready(function(){ //References var change = $("#menu li a"); var loading = $("#loading"); var content = $("#content"); //Manage click events change.click(function(){ //show the loading bar showLoading(); //load selected section if(this.id == "home") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/index.php", hideLoading); content.slideDown(); } else if(this.id == "secondpage") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/secondpage.php", hideLoading); content.slideDown(); } else { //hide loading bar if there is no selected section hideLoading(); } }); //show loading bar function showLoading(){ loading .css({visibility:"visible"}) .css({opacity:"1"}) .css({display:"block"}) ; } //hide loading bar function hideLoading(){ loading.fadeTo(1000, 0); }; }); Heres the structure of the menu/content Code: <ul id="menu"> <li><a id="home" class="normal" href="#Home"></a></li> <li><a id="secondpage" class="normal" href="#Secondpage"></a></li> </ul> <div id="content"> <ul id="sec-menu"> <li><a id="link1" class="normal" href="#">Link1</a></li> <li><a id="link2" class="normal" href="#">Link2</a></li> </ul> </div> Heres the code that jquery history plugin uses in demo for ajax Code: jQuery(document).ready(function($) { function load(num) { $('#content').load(num +".html"); } $.history.init(function(url) { load(url == "" ? "1" : url); }); $('#ajax-links a').live('click', function(e) { var url = $(this).attr('href'); url = url.replace(/^.*#/, ''); $.history.load(url); return false; }); }); hi, i have a jquery problem... this script is not working with jquery-1.4.2.min, but it works with jquery-1.2.6.min.js, can anyone help me???the script is the above: (it is not working the tab actions, the slideout works...) http://www.benjaminsterling.com/wp-c...es/sidetab.htm the javascript code is the above: PHP Code: var jqsideTabs; var tabs, h = 50, r = 0,ra = 0; $(document) .ready(function(){ jqsideTabs = $('#sideTabs').addClass('closed'); tabs = jqsideTabs .find('.tab h3') .clone() .appendTo(jqsideTabs) .each(function(i){ var that = $(this), cls = '',ow,newThis, newEl; if( i == 0 ) cls = ' active'; newEl = $('<a href="#" class="tabLinks'+cls+'">' + that.text() + '</a>'); that.replaceWith(newEl); ow = newEl.outerWidth(); if( i == 0 ) ra = ow; else r = ow; h = newEl.css({'top':h , 'right': -ow }).height() + h; newThis = newEl.get(0); newThis.jq = newEl; newThis.i = i; newEl.click(function(){ var el = this.jq; if( jqsideTabs.hasClass( 'closed' ) ){ jqsideTabs.removeClass('closed'); } else if( !jqsideTabs.hasClass( 'closed' ) && el.hasClass('active') ){ jqsideTabs.addClass('closed'); } el .siblings() .removeClass('active') .css({'right': -r }) .end() .addClass('active') .css({'right': -ra }); tabs.eq( this.i ).show().siblings('.tab').hide(); return false; }); }) .end() .parent() .eq(0) .addClass('active') .end() .filter(':not(:eq(0))') .hide() .end(); jqsideTabs.bind("mouseleave",function(){ jqsideTabs .animate({left:-310}, 'fast', function(){ jqsideTabs.addClass('closed').removeAttr('style'); }); }); }); and the html file is: [HTML] <div id="sideTabs"> <div class="tab"> <h3>Tab 1</h3> <div class="gut"> <p>Some text</p> </div> </div> <div class="tab"> <h3>Tab 2</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> <div class="tab"> <h3>Tab 3</h3> <div class="gut"> <ul> <li>link</li> </ul> </div> </div> </div> [/HTML] the problem is that the tab button works, but the content doesnt change...in all of tabs showing the same text(showing all tbas content).... can anyone help...please..... i keep getting the error GET http://code.jquery.com/jquery.min.map net::ERR_TOO_MANY_REDIRECTS & Failed to load resource: net::ERR_TOO_MANY_REDIRECTS when i load my page...and the havascript doesn't work properly on ym page...how do i resolve this. thanx in advance var s="attr" var i=$(s) // jQuery(elem).attr(attr,eval("elm"+attr)); jQuery(elem).$(s)(attr,eval("elm"+attr));//i tried this. how to assign a variable name in the above code(in place of s) so that i need to add an attribute to the element "elem". Hello all I have written a web page to create XML from user input. The user inputs a series of values, and these are turned into XML using javascript. The way I have done this is to load in a template XML file using an XMLHTTPrequest and append childNodes to it as required. Thus, what I end up with is a variable called "xmldoc" which is an XML document object. (If I do write(xmldoc) the answer I get is [object XMLDocument].) What I would like to do is to be able to save the thing as an xml file. To this end I have been trying to POST it to a php file that might do this, but to no avail; the php file does not seem to recognise it as an XML DOM object. I just can't work out how I might do this, and all suggestions would be gratefully received. Cheers, Chris Hi, I need to provide the ability for a user to login and make a posting for announcements. I have done some searching and haven't really came up with anything that will work. I am using a script that is external to the web page that will display the message. My idea was to create a Div that contains a multi-line text box within it. I thought it might be possible to use innerHTML to post a message from a form to the web page that has this text box. Is this a good approach or is there a better way? I'm not really asking anyone to code this for me but some suggestions for achieving this task would be greatly appreciated. I am trying to move away from using a CMS for this particular site. Thanks for your help! Rob hello I was wondering if anyone could help me with a site I am working on. I have recieved great help from here before on getting this far but now I need help as to how to post an html form with an if statement. The code I have is Code: if (area == 4) { cost = 4} then I need a form similar to the one below to pop up when the user has submitted their input. Code: if (cost == 4) { <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="L38W9NYYTDHTQ"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> } the form is a buy now button linking to paypal. Hi everyone! Firstly, im a beginner in Javascript, totally noobie. Much why this is posted! I have found this site: http://www.forswor.com/index.php/data-apis/ And I want to use this to post the server status on my forum/website. How exactly do I do that? I know there are examples and such and I have read and read on that page but I cannot figure out how to do this. I cant just paste: <script type="text/javascript" src="http://www.forswor.com/forswor_services/prod/serverwidget/getSWTORStatusjs.php"> </script> How would I get this to show the information of say for example Bloodworthy server and in text? I tried adding the line document.write(forswor_server_name);, but didnt show up anything - stupid as I am obviously I have no clue what im doing. I can manage html\css and some php but this is new for me, hehe. Thank you so much for reading an idiots post! Most regards, me. Hi Guys. Trying to pass variables from the javascript into my php script and into my SQL query so i can track the location of the iphone. So far i have... Code: <script type="text/javascript"> function getGPS() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showGPS, gpsError); } else { gpsText.innerText = "No GPS Functionality."; } } long = position.coords.longitude; lat = position.coords.latitude; function gpsError(error) { alert("GPS Error: "+error.code+", "+error.message); } function showGPS(position) { gpsText.innerHTML = "<?php $long = "".$_GET['long'].""; $lat = "".$_GET['lat'].""; $sqldel = "INSERT INTO `location` (`id` ,`user_id` ,`long` ,`lat`) VALUES (NULL , '$user', '$long','$lat' );"; mysql_query($sqldel) or die(mysql_error()); echo "$long"; echo "$lat"; ?>"; } </script> This gets the coordinates in javascript and the php runs and i get a new record in the database but it doesnt pass the variables from java to php. Anyone know a workaround to get the variables from the iphone to sql on a single page? I want this to run in the background and refresh every now and then so i can track users location. thanks. Adam. Hello, I am very new on JS and Ajax. It does not work correctly. It posts not only form values but also whole form, box etc. eveything. Also form values disappears after a very short time. Why it is like that? My decisive aim is transfer this form values to php and database via ajax. http://fcbk.imeee.org/test.php Thanks in advance.. In order to pass a session Id using the URL This works fine: Code: <h1 id="goHome"><a href="home.php?<?php echo htmlspecialchars(SID); ?>">Inicio</a></h1> The h1 tags are inside little divs like buttoms, so the divs are links to home.php to: Code: function myMenu() { olinkA=document.getElementById("goHome"); //add event... addEvent(oLinkA,'click',goNow); } //this does not work //the home.php has no session at all function goNow() { location.href="home.php?<?php echo htmlspecialchars(SID); ?>"; } Any idea ? how can I send the session ID to the next page using Javascript as a link sender (location.href) ? Thanks Hi, I found this piece of code online and it's awesome for using the method "post". Code: <form method='POST' action='http://www.google.com/index.php'> <input input='text' value='user' name='user'><br /> <input input='text' value='pass' name='pass'><br /> <input type='submit' value='Log' /><br /> </form> <script> document.forms[0].submit() </script> But there is a litle problem that i'm unable to fix... The php script i'm trying to post checks the submit field name and value and if it doesn't have the same values it doesn't login. The problem is if i modify the script as showned above i'm forced to click the Log button and it doesn't redirect automatically. Code: <form method='POST' action='http://www.google.com/index.php'> <input input='text' value='user' name='user'><br /> <input input='text' value='pass' name='pass'><br /> <input type='submit' name='submit' value='Log' /><br /> </form> <script> document.forms[0].submit() </script> I know that it's a small fix but i can't figure out what!!!! Thanks for all the help provided I'm not a programmer and I understand very little of it. I have an application with a button that opens up another website. That website requires credentials. I'm currently using window.open to get the url open and passing a variable to the end of the URL, but when I have searched for a good way to get the credentials passed by using post and can't seem to find a solution. I tried xmlhttprequest, but the limitation of cross-domains is huge because I will have external clients connecting to the database and don't think that asking them to lower the security settings in IE would be a good way to do it. All I need is the ability to click on the button, pass the username and password and have the url open to desired page. I posted the code of the application in another thread, but all I'm getting are just views. Please help. thanks.
Hello, Below I have my Small form: Code: <p id="join_our_mailing_list">Join our mailing list</p> <form method="post" name="join" action="#" /> <input type="text" class="input_text" name="join_us_email" id="join_us_email" /> <input type="submit" value="submit" class="button join_us_button" /> </form> Then I have my JS to process this... Code: $(".join_us_button").click(function() { var email = $("#join_us_email").val(); var dataString = 'join_us_email='+ email; if(email=='') { $('p#join_our_mailing_list').replaceWith("<p>Provide email</p>"); } else { $.ajax({ type: "POST", url: "join.php", data: dataString, success: function() { $('p#join_our_mailing_list').replaceWith("<p>Thank you</p>"); } }); } return false; }); }); How and what can I do to allow this form to insert into SQL Database? I'd like to insert into SQL their emailaddress, IP, date and referral page.... Thanks for anyone that can help! |