Jump to content

Search the Community

Showing results for tags 'ajax'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. hello i'm creating an ajax chat system and everything is working fine but the problem, i'm facing is that i can't replace some part of the message with the emotion kept in the array... If i run only the emotion script then its working fine but i can't immplement with the chat system.. Any body plz help... <?php ob_start(); session_start(); ?> <style> body{ background-color: grey; } #box{ width: 326px; height: 432px; border: 1px solid activeborder; margin: 0px auto; } #box1{ width: 326px; height: 400px; background-color: #eee; margin-bottom: 10px; } </style> <form method="post" action=""> <div id="box"> <div id="box1"> <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db(chat) or die(mysql_error()); $req = mysql_query("SELECT * FROM msg") or die(mysql_error()); while($row = mysql_fetch_array($req)){ $m = $row['message']; echo "<div id='message'> $m </div>"; } ?> </div> <input type="text" id="chat" size="50" /> <input type="button" name="submit" value=" Chat " onclick="sendmessage()" /> </div> </form> <script> function sendmessage() { var msg = document.getElementById("chat").value; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("box1").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","chat_msg.php?m="+msg,true); xmlhttp.send(); } </script> and the chat_msg.php code is <?php session_start(); mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db(chat) or die(mysql_error()); $sess = session_id(); $mg = $_REQUEST['m']; $sql = mysql_query("INSERT INTO msg VALUES('','$sess','$mg')") or die(mysql_error()); $req = mysql_query("SELECT * FROM msg") or die(mysql_error()); while($row = mysql_fetch_array($req)){ $m = $row['message']; echo "<div id='message'> $m </div>"; } ?> and the emotion code is $str = $_REQUEST['comment']; $emo = array("<3", "#12", "@153", "#45", "@352"); $img = array("<img src='emotions/1.png' height='113' width='120' alt='ugly' />", "<img src='emotions/2.png' height='113' width='120' alt='happy' />", "<img src='emotions/3.png' height='113' width='120' alt='love' />", "<img src='emotions/4.png' height='113' width='120' alt='sweet' />", "<img src='emotions/5.png' height='113' width='120' alt='smiley' />"); $new_str = str_replace($emo, $img, $str); echo "<hr />"; echo $new_str; } ?> i can;t figure where to put the emotion code so that it will work like facebook chat system. Any help will be greatly appreciated... Thank u.
  2. Hi all, This problem is killing me. I hope / pray someone can help. Essentially I need to pass a JS variable to a PHP variable without refresh/form submission or redirecting. I'm new to Ajax so please be patient The owner of this site generally lives in 3 countries lucky ******. When he logs in he wants the contact page updated with his current number. I have a form with hidden fields that return the address location using an ajax call to ipinfo.io - this works fine. <script> $(function() { var admin = <?php echo json_encode($admin->isAdmin($user['username'])); ?>; var phone=""; if(admin == true){ $.ajax({ url:"http://ipinfo.io", dataType:'jsonp' }) .success(function(response){ $("#address").val(response.country); $("input[id=address]").val(response.country); var testLoc = $('#address').val(); if(testLoc == "GB"){ phone = "<?php echo $gb?>"; $("#phone").append(phone); }else if(testLoc == "GABON"){ phone = "<?php echo $gabon?>"; $("#phone").append(phone); }else if(testLoc == "THAILAND"){ phone = "<?php echo $thai?>"; $("#phone").append(phone); } }); var time = new Date(); $("#localTime").append(time); }else{ //alert("Not Admin"); $("#phone").append(phone); } }); </script> The above essentuially checks to see that he is THE admin, if it is it then sets the hidden field value to be the country, that is then placed in the testLoc variable and depending on what it is, it spits out the number. This all works well unless of course you visit the site and you're not the admin. All you see is an empty string. I need to get that phone variable or location variable, either of them really from the js into a php variable. That way when a normal joey visits the page I can just echo out that variable instead. phone or location var in js script to php variable?
  3. Hi all, I would like to create a function that allows two options to be selected and then on pressing submit it loads in content dynamically. How can I create such a feature ? Any help would be much appreciated
  4. Hi all, I really need some help on this one. I've created a very complex page with a number of buttons that load content in dynamically. (There are quite a few combinations) What I would like to know is, is there a way to hard-code if an option is selected on one page that that selection stay open on another page ? For example I'm on the globe.html page having selected option 3. I open the view.html page and that page starts on option 3 due to it being selected on the previous page. Any help would be very appreciated
  5. Hello, I am trying to create an array where by the items listed are nested with the names and the array spat out is easy to use when I am creating an ajax function with data from it all. Below is an idea of what I need to do: # This is where I am grabbing the data from the instagram class $data_url[] = $data->images->standard_resolution->url; $data_link[] = $data->link; $data_id[] = $data->getId(); $data_likes[] = $data->likes->count; {["images":[ ["data_url":[ ["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg"] ], ["data_link":[ ["http:\/\/instagram.com\/p\/cq2pjLMNNE\/"] ], ["data_id": [516465457066201924_288233123] ], ["data_likes": [18] ] ] ] } In my current ajax.php page, I am creating a place where data can be captured and I can use it to get the images and place them into a page. Here is what I have got so far: $instagram = new Instagram\Instagram; $instagram->setAccessToken($_SESSION['instagram_access_token']); $token = $_SESSION['instagram_access_token']; //$clientID = $_SESSION['client_id']; $current_user = $instagram->getCurrentUser(); $tag = $instagram->getTag('folkclothing'); $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null); /* $params = isset( $_GET['max_tag_id'] ) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null; */ /* $media = $tag->getMedia($params); */ /* $next_page = $media->getNext(); */ /* // Receive new data $imageMedia = $instagram->pagination($media); */ // Collect everything for json output $images = array(); $data_link = array(); $data_id = array(); $data_likes = array(); foreach ($media as $data) { $images[] = array($data_url[] = $data->images->standard_resolution->url,$data_link[] = $data->link, $data_id[] = $data->getId(), $data_likes[] = $data->likes->count); } echo json_encode(array( 'next_id' => $media->getNextMaxTagId(), 'images' => $images )); Below is what my /ajax/ url gives me: {"next_id":"1374887530845","images":[["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg","http:\/\/instagram.com\/p\/cq2pjLMNNE\/","516465457066201924_288233123",18],["http:\/\/distilleryimage10.s3.amazonaws.com\/46f790e0fdaf11e29de622000ae90e7b_7.jpg","http:\/\/instagram.com\/p\/coEUD0MyGO\/","515681128006492558_197168271",23],["http:\/\/distilleryimage6.s3.amazonaws.com\/7e510fa6fcee11e29a4b22000a1fb593_7.jpg","http:\/\/instagram.com\/p\/clmYo1AgU6\/","514986551277651258_20025128",25],["http:\/\/distilleryimage0.s3.amazonaws.com\/4f41be96fc3411e2829822000a9f1487_7.jpg","http:\/\/instagram.com\/p\/cjN3PipYkE\/","514315753313634564_190097401",10],["http:\/\/distilleryimage0.s3.amazonaws.com\/bcc8d83cfb9911e2921e22000aa81fd0_7.jpg","http:\/\/instagram.com\/p\/chPPNdGDhI\/","513758848433535048_6206549",13],["http:\/\/distilleryimage2.s3.amazonaws.com\/ef97af2efb5611e2b16122000a1f9e61_7.jpg","http:\/\/instagram.com\/p\/cgYg4ljpby\/","513518170419402482_52465932",1],["http:\/\/distilleryimage5.s3.amazonaws.com\/8e7bbf04fa9e11e2aea022000a9d0ee7_7.jpg","http:\/\/instagram.com\/p\/ceBeGXNpA9\/","512853874029531197_20203491",2],["http:\/\/distilleryimage4.s3.amazonaws.com\/96dc4444f9f811e2b88d22000a1fd1dd_7.jpg","http:\/\/instagram.com\/p\/cb5gooAgW4\/","512255913931965880_20025128",6],["http:\/\/distilleryimage11.s3.amazonaws.com\/6b80e884f9dc11e29b2522000a9f13d5_7.jpg","http:\/\/instagram.com\/p\/cbibv3JW9H\/","512154423034998599_430907394",20],["http:\/\/distilleryimage7.s3.amazonaws.com\/64f82bd6f95411e2a73522000a1faf50_7.jpg","http:\/\/instagram.com\/p\/cZzAF8syFb\/","511664339442409819_197168271",16],["http:\/\/distilleryimage10.s3.amazonaws.com\/b54645f4f93711e283e622000a1fb86d_7.jpg","http:\/\/instagram.com\/p\/cZbgGrlSzW\/","511560986135964886_187431354",17],["http:\/\/distilleryimage8.s3.amazonaws.com\/a9fc18a2f87111e29c8b22000a9f18f4_7.jpg","http:\/\/instagram.com\/p\/cW5Q5CBrlw\/","510847457153169776_378485429",6],["http:\/\/distilleryimage0.s3.amazonaws.com\/55b6269cf86311e2b5f422000a1f9a34_7.jpg","http:\/\/instagram.com\/p\/cWthoKit5E\/","510795830715407940_203990694",16],["http:\/\/distilleryimage9.s3.amazonaws.com\/bff691e2f82a11e2939b22000a1f9251_7.jpg","http:\/\/instagram.com\/p\/cV_K8mBu9R\/","510591961963884369_256035442",12],["http:\/\/distilleryimage4.s3.amazonaws.com\/5ef4c3c0f73811e2890322000a9e48f1_7.jpg","http:\/\/instagram.com\/p\/cS4nTwwE_U\/","509718699729506260_37194114",34],["http:\/\/distilleryimage8.s3.amazonaws.com\/a1b5f0acf6cb11e2957722000a1f9a39_7.jpg","http:\/\/instagram.com\/p\/cRfiPgmAWQ\/","509326925426591120_453101536",11],["http:\/\/distilleryimage6.s3.amazonaws.com\/4bf62240f68511e29aee22000a9f38e6_7.jpg","http:\/\/instagram.com\/p\/cQl6qiBzdu\/","509073517011482478_5670460",223],["http:\/\/distilleryimage1.s3.amazonaws.com\/d23848d6f61e11e2807c22000a9e06c7_7.jpg","http:\/\/instagram.com\/p\/cPR9_otpGt\/","508704309923713453_20203491",6]]} Can anyone guide me into the best way I can do this so it gives me an array from my ajax.php so I can grab the data and place it into my page better? I have tried numerous techniques but they have not worked at all. Thanks, Mark
  6. Not sure how to go about this task but I imagine it requires some sort of foreach loop I have a drop down list populated by a label called LST_Type, this table only exists to provide options for this dropdown list The value selected on the dropdown menu gets written to a table called "assets". when the users clicks away from the form (using ajax) Here is what I need to happen: On page load the dropdown list need its default option to be whatever the current value of the record is in the "asset" table. As the only way you can insert data into this field is via the dropdown list it will always be somethig from the "LST_Type" table The reason is that the data is written to the fields when you click away from the input boxes and unless you are editing the "Type" record it updates it to its default selection. hope this makes sense here is my code: <tr id="<?php echo $id; ?>" class="edit_tr"> <!-- Title Colum --><td class="style4" style="font-size:14px;width:200; height:35px; class="edit_td"> Type: </td> <td style="font-size:14px;width:270px;border:solid 0px #000;padding:0px; class="edit_td"> <span style="color:#0066CC;" id="type1_<?php echo $id; ?>" class="text"><?php echo $Type; ?></span> <!-- ***************************************START - This Is the dropdown menu script *********************************************** --> <script type="text/javascript"> function OnDropDownChange2(dropDown) { var selectedValue = dropDown.options[dropDown.selectedIndex].value; document.getElementById("type1_input_<?php echo $id; ?>").value = selectedValue; } </script> <select name = "MYtype" id="type1_input_<?php echo $id; ?>" class="editbox" onChange="OnDropDownChange2(this);">> <?php $sql = mysql_query("SELECT Type FROM LST_Type"); while ($row = mysql_fetch_array($sql)){ echo "<option value='" . $row['Type'] . "'>" . $row['Type'] . "</option>"; } ?> </select> <input type="text" value="<?php echo $Type; ?>" class="editbox" id="type1_input_<?php echo $id; ?>" /> /> <!-- ***************************************END *********************************************** -->
  7. I am trying to send data from page1.php to page2.php with ajax, can someone tell me how to send data from page1 to page2 and then insert it into database, also tell me that after inserting the values in database, it must display the message on html page "data has been saved !!!"... I am trying to display message by document.getElementById('message').innerHTML = "Your data has been saved"...........
  8. I am building a relatively small app in laravel. Currently I am trying to create a load more button to load more images into a container in the view. Would anyone know when clicking load more I get an internal server error? Here is my set up: View for my images: $instagram = new Instagram\Instagram; $instagram->setAccessToken($_SESSION['instagram_access_token']); $token = $_SESSION['instagram_access_token']; //$clientID = $_SESSION['client_id']; $current_user = $instagram->getCurrentUser(); $tag = $instagram->getTag('folkclothing'); $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null); $liked_media = $current_user->getLikedMedia(); echo '<section id="images">'; foreach ( $media as $item ) { echo '<article class="instagram-image">'; // define the form and set the action to POST to send the data to this script echo '<form class="forms" action="'; echo URL::current(); echo '" method="post">'; $id = $item->getId(); echo '<a class="fancybox" href="' . $item->link . '"><img src="' . $item->images->standard_resolution->url . '" /></a>'; if ( $current_user->likes($item) ){ echo '<button class="ajax instabtn unlike icon-heart" type="submit" name="action" value="Unlike"></button>'; } else { echo '<button class="ajax instabtn like icon-heart" type="submit" name="action" value="Like"></button>'; } echo '<input type="hidden" name="id" value="'; echo $id; echo '">'; echo '<p>'; echo $item->likes->count; echo '</p>'; //echo '<p>'.$item->getId().'</p>'; //echo '<p>By: <em>' . $item->user->username . '</em> </p>'; //echo '<p>Date: ' . date('d M Y h:i:s', $item->created_time) . '</p>'; //echo '<p>$item->comments->count . ' comment(s). ' . $item->likes->count . ' likes. '; echo '</form>'; echo '</article>'; } echo '</section>'; Here the instagram class generates the images and puts them into the div through a loop. Below is a load more button storing the data need in it. Load more button: echo "<br><button id=\"more\" data-maxid=\"{$media->getNextMaxTagId()}\" data-tag=\"{$tag}\">Load more ...</button>"; And then there is an ajax view that stores the relevant data for the images to be found for the next page: <?php // set up autoloader function app_autoloader($class) { include './' . $class . '.php'; } spl_autoload_register('app_autoloader'); // Initialize class for public requests $instagram = new Instagram\Instagram; // Receive AJAX request and create call object $tag = $_GET['tag']; $clientID = $instagram->getApiKey(); $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null); $call = new stdClass; $call->next_max_id = $maxID; $call->next_url = "https://api.instagram.com/v1/tags/{$tag}/media/recent?client_id={$clientID}&max_tag_id={$media->getNextMaxTagId()}"; // Receive new data $media = $instagram->pagination($call); // Collect everything for json output $images = array(); foreach ($media->data as $data) { $images[] = $data->images->standard_resolution->url; } echo json_encode(array( 'next_id' => $media->getNextMaxTagId, 'images' => $images )); This page finds the tag and gets the media for that tag and finds the next_max_id. In my jquery I use and ajax call to get this data and load the images into my div but instead I get an internal server error like so: Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://client:8888/ajax?tag=client&max_tag_id=1374869525975&_=137571153802 Does anyone have an idea why it would not produce the results? I know its not too far off. Thanks, Mark ajax.blade.php image.blade.php
  9. Not sure how to go about this task but I imagine it requires some sort of foreach loop I have a drop down list populated by a label called LST_Type, this table only exists to provide options for this dropdown list The value selected on the dropdown menu gets written to a table called "assets". when the users clicks away from the form (using ajax) Here is what I need to happen: On page load the dropdown list need its default option to be whatever the current value of the record is in the "asset" table. As the only way you can insert data into this field is via the dropdown list it will always be somethig from the "LST_Type" table The reason is that the data is written to the fields when you click away from the input boxes and unless you are editing the "Type" record it updates it to its default selection. hope this makes sense here is my code: <tr id="<?php echo $id; ?>" class="edit_tr"> <!-- Title Colum --><td class="style4" style="font-size:14px;width:200; height:35px; class="edit_td"> Type: </td> <td style="font-size:14px;width:270px;border:solid 0px #000;padding:0px; class="edit_td"> <span style="color:#0066CC;" id="type1_<?php echo $id; ?>" class="text"><?php echo $Type; ?></span> <!-- ***************************************START - This Is the dropdown menu script *********************************************** --> <script type="text/javascript"> function OnDropDownChange2(dropDown) { var selectedValue = dropDown.options[dropDown.selectedIndex].value; document.getElementById("type1_input_<?php echo $id; ?>").value = selectedValue; } </script> <select name = "MYtype" id="type1_input_<?php echo $id; ?>" class="editbox" onChange="OnDropDownChange2(this);">> <?php $sql = mysql_query("SELECT Type FROM LST_Type"); while ($row = mysql_fetch_array($sql)){ echo "<option value='" . $row['Type'] . "'>" . $row['Type'] . "</option>"; } ?> </select> <input type="text" value="<?php echo $Type; ?>" class="editbox" id="type1_input_<?php echo $id; ?>" /> /> <!-- ***************************************END *********************************************** -->
  10. Hello everyone! I've been at this WordPress AJAX functionality for almost 2 weeks and I've had it working in a basic state for about 2 days. However passing along geolocation data WITH the $.ajax data is ruining my life. Here's what's going on: // click "trigger" function $("#searchsubmit").click(function(e){ e.preventDefault(); // data: object data = { action:'wpa56343_search', latitude: $('input#latitude').attr('value'), longitude: $('input#longitude').attr('value') }; _do_ajax(data); }); // end click func function _do_ajax(obj) { console.log(obj); $.ajax({ type:"POST", url: My_Obj.ajaxurl, // the request is sent to admin-ajax.php data: data, dataType: 'json', success: function( response ){ loops and stuff } WordPress is very specific as to the ways you can do AJAX requests. If you're not familiar with them: The above queries a wp_ajax_ACTION in functions.php. My action function is called wpa56343_search. This function is where I need to include post variables for use within the query it performs. The way it is working now logs Object {action: "wpa56343_search", latitude: "42.041261299999995", longitude: "-70.9414206"} Now why can't I get these through traditional methods such as: $latitude = $_POST['latitude']; $longitude = $_POST['longitude']; // to use within the query function function my_ajax_search($latitude, $longitude){ query here }
  11. <?php /* Template Name: Warranty New */ //Include the database class require("report/db.class1.php"); ?> <script type="text/javascript" src="/addjs/jquery_003.js"></script> <script type="text/javascript" src="/addjs/chainedselects.js"></script> <script type="text/javascript" src="/addjs/contentwarranty.js"></script> <link rel="stylesheet" href="/Reports/warranty.css" type="text/css" media="screen" /> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <script src="/Reports/jquery.validate.js"></script> <script src="http://jquery.bassistance.de/validate/additional-methods.js"></script> <script type="text/javascript"> $(function() { var scntDiv = $('#p_scents'); var i = $('#p_scents div').size() + 1; $('#addScnt').on('click', function() { if ($('input#wproserial[]'+(i-1)).val() != '') { $('<table class="multiple-rows" ><tr class="prod-row prod-row"><td><input type="text" name="wwarrantycard[]'+i+'" id="wwarrantycard'+i+'" class="textinput2 required" autocomplete="off" value=""/></td><td><select class="selectbox " id="maker'+i+'" name="makes[]'+i+'"></select></td><td><select name="types[]'+i+'" id="typer'+i+'" class="selectbox "></select></td><td><select name="models[]'+i+'" id="modelr'+i+'" class="selectbox " ></select></td><td><input name="wproserial[]'+i+'" id="wproserial'+i+'" type="text" value="" class="textinput3"></td><td width="20px" style="text-align:center"><a href="javascript:void(0);" id="remScnt'+i+'" class="remScnt">X</a></td></tr></table>').appendTo(scntDiv); } else { alert('Enter your product first!'); $('input#wproserial[]'+(i-1)).focus(); } var1="maker"+i; var1_1=document.getElementById(var1); var2="typer"+i; var2_1=document.getElementById(var2); var3="modelr"+i; var3_1=document.getElementById(var3); initListGroup('vehicles', var1_1, var2_1, var3_1, 'cs'); document.getElementById(var1).selectedIndex=""; document.getElementById(var2).selectedIndex="" document.getElementById(var3).selectedIndex="" i++; return false; }); $('#p_scents').on('click', '.remScnt', function() { if (i > 1) { $(this).parents('table').remove(); i--; } return false; }); }); </script> <script type="text/javascript"> $(function() { $( "#wdatepurchase" ).datepicker({ dateFormat: 'dd-mm-yy', }); $( "#wdob" ).datepicker({ dateFormat: 'dd-mm-yy', changeMonth: true, changeYear: true, yearRange: "1950:2003", onSelect: function() { $( "#datepicker" ).trigger('blur'); } }); }); $(document).ready(function() { $.validator.addMethod("dateRule", function(value, element) { return value.match(/^(0[1-9]|[12][0-9]|3[01])[- //.](0[1-9]|1[012])[- //.](19|20)\d\d$/); }, "Please enter a date in the format dd/mm/yyyy" ); $('form.warregform').on('submit', function(event) { // adding rules for inputs with class 'first' $('#wfirstname').each(function() { $(this).rules("add", { required: true, minlength: 3, messages: { required: "Type your first name!", minlength: jQuery.format("Please, at least {0} character are necessary!") } }) }); // adding rules for inputs with class 'last' $('#wlastname').each(function() { $(this).rules("add", { required: true, minlength: 3, messages: { required: "Type your last name!", minlength: jQuery.format("Please, at least {0} character are necessary!") } }) }); // adding rules for inputs with class 'last' $('#wyourphone').each(function() { $(this).rules("add", { required: true, number: true, minlength: 9, messages: { required: "Type you contact number! (eg. 015679322)!", minlength: jQuery.format("Please, at least {0} number are necessary!") } }) }); // adding rules for inputs with class 'last' $('#wdatepurchase').each(function() { $(this).rules("add", { required: true, minlength: 10, dateRule: true, messages: { required: "Insert your Purchase Date (dd-mm-yyyy)!", date: "Please enter a valid date.", minlength: jQuery.format("Please, at least {0} are necessary!") } }) }); // adding rules for inputs with class 'comment' $('input.textinput2').each(function() { $(this).rules("add", { required: true, number: true, minlength: 3, messages: { required: "Type warranty cards number!", minlength: jQuery.format("Please, at least {0} number are necessary") } }) }); // adding rules for inputs with class 'comment' $('select.selectbox').each(function() { $(this).rules("add", { required: true, messages: { required: "", } }) }); // adding rules for inputs with class 'comment' $('input.textinput3').each(function() { $(this).rules("add", { required: true, minlength: 3, remote: "report/user_check.php", messages: { required: "Type Serial number!", minlength: jQuery.format("Please, at least {0} character are necessary"), remote: jQuery.format("{0} is already taken"), // remote: 'This email address has already been used' } }) }); // adding rules for inputs with class 'last' $('#wshoplocation').each(function() { $(this).rules("add", { required: true, messages: { required: "Choose Shop Location!", } }) }); // test if form is valid if($('form.warregform').validate().form()) { console.log("validates"); } else { console.log("does not validate"); } }) // initialize the validator $('form.warregform').validate(); }); </script> <?php $hasErrors = false; //If form was submitted if (isset($_POST['btnSubmit'])) { for ( $i=0;$i<count($_POST['wwarrantycard']);$i++) { { $wwarrantycard = $_POST['wwarrantycard'][$i]; $makes = $_POST['makes'][$i]; $types = $_POST['types'][$i]; $models = $_POST['models'][$i]; $wproserial = $_POST['wproserial'][$i]; } } if(empty($_POST['wfirstname'])){ $nameErr = "With more than 3 letters!"; $hasErrors = true; }if(empty($_POST['wlastname'])){ $nameErr = "With more than 3 letters!"; $hasErrors = true; }else if (empty($_POST['wyourphone'])){ $phoneErr = "With more than 7 Numeric! (eg. 015679322)"; $hasErrors = true; }else if(strlen($_POST['wyourphone']) <= 7){ $phoneEErr = "With more than 7 Numeric! (eg. 015679322)"; $hasErrors = true; }else if (empty($wwarrantycard)){ $wcardErr = "Missing insert product after you click add more product. Please insert and try again!!!"; $hasErrors = true; }else if (empty($makes)){ $wcardErr = "Missing insert product after you click add more product. Please insert and try again!!!"; $hasErrors = true; }else if (empty($types)){ $wcardErr = "Missing insert product after you click add more product. Please insert and try again!!!"; $hasErrors = true; }else if (empty($wproserial)){ $wcardErr = "Missing insert product after you click add more product. Please insert and try again!!!"; $hasErrors = true; }else if (empty($_POST['wshoplocation'])){ $shopErr = "Please Select Shop Location."; $hasErrors = true; } else{ } } ?> <?php if (!isset($_POST['btnSubmit']) || $hasErrors) { ?> <body onLoad="initListGroup('vehicles', document.warrantyform.maker, document.warrantyform.typer, document.warrantyform.modelr, 'cs'); resetListGroup('vehicles');" > <div class="divider"></div> <div class="clear"></div> <form name="warrantyform" id="warrantyform" class="warregform" enctype="multipart/form-data" autocomplete="OFF" method="post"> <div class="warrleft"> <label class="labeln"><strong>First Name: * </strong> <span id="nameInfo"></span></label> <label for="wfirstname" class="error"></label> <input class="textinput " type="text" name="wfirstname" id="wfirstname" size="30" maxlength="60" value="" autocomplete="off"/> </div> <div class="warrleft"> <label class="labeln"><strong>Last Name: * </strong> <span id="nameInfo"></span></label> <label for="wlastname" class="error"></label> <input class="textinput " type="text" name="wlastname" id="wlastname" size="30" maxlength="60" value="" autocomplete="off"/> </div> <div class="clear"></div> <div class="warrleft"> <label class="labeln"><strong>Your Email: </strong> <span id="emailInfo">NOTE: Warranty confirmation will be sent to your email address</span></label> <input class="textinput " type="text" name="wyouremail" id="wyouremail" size="30" maxlength="60" value="" autocomplete="off"/> </div> <div class="warrleft"> <label class="labeln"><strong>Contact Number: * </strong> <span id="wcontactInfo"></span></label> <label for="wyourphone" class="error"></label> <input class="textinput " type="text" name="wyourphone" id="wyourphone" size="30" maxlength="60" value="" autocomplete="off"/> </div> <div class="clear"></div> <div class="warrleft"> <label class="labeln"><strong>Gender: </strong></label><br/> <select name="wgender" id="wgender" > <option value="Male">Male</option> <option value="Female">Female</option> </select> </div> <div class="warrleft"> <label class="labeln"><strong>Date Of Birth: </strong></label><br/> <input class="textinput " type="text" name="wdob" id="wdob" size="30" maxlength="60" value="" autocomplete="off" readonly/> </div> <div class="clear"></div> <div class="warrleft"> <label class="labeln"><strong>Company Name: </strong></label><br/> <input type="text" maxlength="100" value="" name="wcompanyname" id="wcompanyname" class="textinput" autocomplete="off"> </div> <div class="warrleft"> <label class="labeln"><strong>Job Title: </strong></label><br/> <input type="text" maxlength="100" value="" name="wjobtitle" id="wjobtitle" class="textinput" autocomplete="off"> </div> <?php $todays_date = date("d-m-Y"); ?> <div class="warrleft"> <label class="labeln"><strong>Date of Purchase: * </strong></label> <label for="wdatepurchase" class="error"></label> <input type="text" maxlength="100" value="<?php echo $todays_date; ?>" name="wdatepurchase" id="wdatepurchase" class="textinput" autocomplete="off"> </div> <div class="clear"></div> <span id="wcardInfo"></span> <table class="multiple-rows" > <tr class="prod-row2"> <td><label><strong>Warranty Card No: *</strong> </label></td> <td><label><strong>Product Category *</strong></label></td> <td><label><strong>Sub Category *</strong></label></td> <td><label><strong>Model Name *</strong></label></td> <td><label><strong>Serial Number *</strong></label></td> <td width="20px"> </td> </tr> <tr class="prod-row prod-row"> <td><input type="text" name="wwarrantycard[]" id="wwarrantycard0" value="" class="textinput2 " autocomplete="off"/></td> <td><select name="makes[]" id="maker" class="selectbox "></select></td> <td><select name="types[]" id="typer" class="selectbox "></select></td> <td><select name="models[]" id="modelr" class="selectbox "></select></td> <td><input name="wproserial[]" id="wproserial0" type="text" value="" class="textinput3 " autocomplete="off"></td> <td> </td> </tr> </table> <div id="p_scents"></div> <div class="addproducts"><a href="javascript:void(0);" id="addScnt">Add another product</a></div> <div class="clear"></div> <div class="warrleft"> <label class="labeln"><strong>Shop Location: * </strong><span id="wshopInfo"></span></label> <label for="wshoplocation" class="error"></label> <select name="wshoplocation" id="wshoplocation" > <option value="">Select Shop</option> <option value="I-Qlick">I-Qlick</option> <option value="CS_KTH">CS_KTH</option> <option value="CS_Ahhoo">CS_Ahhoo</option> <option value="CS_Sunsimexco">CS_Sunsimexco</option> <option value="Other">Other</option> </select> </div> <div class="warrleft"> <label class="labeln"><strong>Rate Shop Service:</strong></label> <select class="" name="wrate" id="wrate"> <option value="Very Good">Very Good</option> <option value="Good">Good</option> <option value="Normal">Normal</option> <option value="Bad">Bad</option> </select> </div> <div class="clear"></div> <div class="warrleft"> <input type="checkbox" name="wpromo" id="wpromo" value="Yes" /> <strong>I want to receive i-Qlick's promotions by email.</strong></p> </div> <div class="clear"></div> <div class="warrleft"> <input id="go" name="btnSubmit" type="submit" value="Submit" class="btn"/> <!--<input id="go" name="btnSubmit" type="submit" value="Submit" class="btn" onClick="targetGroup('textinput2');"/>--> <input type="reset" value="Reset" onClick="resetListGroup('vehicles')" > </div> </form> <!--<script type="text/javascript" src="<php bloginfo( 'url' ); ?>/Reports/validation.js"></script>--> <?php } ?> above is My Html Files... I can't check validation with existing database, this serial no. is already register or not. every input data is showing message "is already taken". so i can't submit. My Serial no input field is unlimited. user_check.php <?php include("db.class1.php"); if (isset($_POST['wproserial'])) { //create instance of database class $db = new mysqldb(); $db->select_db(); for ( $i=0;$i<count($_POST['wproserial']);$i++) { { $wproserial = $_POST['wproserial'][$i]; } } //$query = "SELECT * FROM products WHERE SerailNo"; //$query = "SELECT * FROM products WHERE SerailNo='".$wproserial."'"; //$query = "SELECT * FROM products WHERE SerailNo='$wproserial'"; $query = "SELECT * FROM `products` WHERE `SerailNo` = '".mysql_real_escape_string($wproserial)."'"; //$query = "SELECT EXISTS (SELECT * FROM products WHERE SerailNo='".mysql_real_escape_string($wproserial)."')"; if($db->num_rows($db->query($query)) < 1) { /*return true; }else { return false; } */ $valid = 'true'; }else { $valid = 'false'; } echo json_encode($valid); } ?>
  12. I am building an asset managment system, utilizing some code I found on the net which does live record updates using AJAX, the code is great if I rememeber the link I will post it. However the example code only contains database fields and I need about 14ish, so with my little understanding of the code i started adding more fields. for some reason every time I try to insert the "condition" field the live update stops working for all fields. you can type in new data but does not save back to the database. It happends when i change the code from this: $sql = "update fullnames set AssetID='$AssetID',SerialNumber='$SerialNumber',Type='$Type',Model='$Model' ,Location='$Location' ,Make='$Make' where id='$id'"; mysql_query($sql); to this $sql = "update fullnames set AssetID='$AssetID',SerialNumber='$SerialNumber',Type='$Type',Model='$Model' ,Location='$Location' ,Condition='$Condition ,Make='$Make' where id='$id'"; mysql_query($sql); the full code is attached. I would really apprisiate any help assets.php table_ajax_edit.php
  13. I am new to php and I've got a query for all you professionals, I have this script which is meant to send emails to me but what I want to do is instead of redirecting the user(s) to a different page to display the results I would like for it to show the success message or fail message on the same page as the form. I hope I am making my self clear. I would like to know if you could tell me how to implement it. index.html: <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="send_form_email.php" id="contactform" method="post" name= "contactform"> <table width="450px"> <tr> <td valign="top"><label for="title">Title *</label></td> <td valign="top"><input maxlength="50" name="title" size="30" type="text"></td> </tr> <tr> <td></td> </tr> <tr> <td valign="top"><label for="fname">First Name *</label></td> <td valign="top"><input maxlength="50" name="fname" size="30" type="text"></td> </tr> <tr> <td></td> </tr> <tr> <td valign="top"><label for="mname">Middle Name</label></td> <td valign="top"><input maxlength="50" name="mname" size="30" type="text"></td> </tr> <tr> <td valign="top"><label for="lname">Last Name *</label></td> <td valign="top"><input maxlength="50" name="lname" size="30" type="text"></td> </tr> <tr> <td valign="top"><label for="suffix">Suffix</label></td> <td valign="top"><input maxlength="80" name="suffix" size="30" type="text"></td> </tr> <tr> <td valign="top"><label for="message">Message *</label></td> <td valign="top"> <textarea cols="25" maxlength="1000" name="message" rows="6"> </textarea></td> </tr> <tr> <td></td> </tr> <tr> <td valign="top"><label for="email">Email Address *</label></td> <td valign="top"><input maxlength="80" name="email" size="30" type="text"></td> </tr> <tr> <td colspan="2" style="text-align:center"><input type="submit" value="Submit"></td> </tr> </table> </form> </body> </html> send_form_email.php: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "test@gmail.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['title']) || !isset($_POST['fname']) || !isset($_POST['mname']) || !isset($_POST['lname']) || !isset($_POST['suffix']) || !isset($_POST['message']) || !isset($_POST['email'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $title_name = $_POST['title']; // required $first_name = $_POST['fname']; // required $middle_name = $_POST['mname']; $last_name = $_POST['lname']; // required $suffix_name = $_POST['suffix']; $message = $_POST['message']; // required $email_from = $_POST['email']; // required $error_message = ""; $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$title_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$middle_name)) { $error_message .= 'The Middle Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$suffix_name)) { $error_message .= 'The Suffix Name you entered does not appear to be valid.<br />'; } if(strlen($message) < 2) { $error_message .= 'The Message you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Title Name: ".clean_string($title_name)."\n"; $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Middle Name: ".clean_string($middle_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Last Name: ".clean_string($suffix_name)."\n"; $email_message .= "Comments: ".clean_string($message)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> <center>Thank you for contacting us. We will be in touch with you very soon.</center> <?php } ?> If you're confused about anything please let me know.
  14. Hi guys, I have a relatively hard question. The problem is that I must leave the HTML code as it is and not put any divs around the image tags. How can I add a class or a selector to an image tag so that I can style that specific image tag for a specific style sheet. The reason why I'm doing this is because my code is styled in three different style sheets for responsive web design. I need a way to select these image tags using an identifier without affect the html code to go crazy in other layouts. <img src="./ajaxfiles/globebuttons/1xtremevision.png" alt="" name="btn3" id="btn3" onclick="MM_swapImage('car','','./ajaxfiles/carbackgrounds/XtremeVision-E-City.jpg','btn1','','./ajaxfiles/globebuttons/1standardreplacement.png','btn2','','./ajaxfiles/globebuttons/1powervision.png','btn3','','./ajaxfiles/globebuttons/xtremevision.png','btn4','','./ajaxfiles/globebuttons/1bluevisionultra.png','btn5','','./ajaxfiles/globebuttons/1crystalvision.png','btn6','','./ajaxfiles/globebuttons/1diamondvision.png',1)" /> Any help would be much appreciated, please post a way to style these image tags ? All the best, Adam
  15. my session value automatically changes, when i submit my form . actually i am using ajax in one of the fields in form. and when i submitthe form, my session value changes automatically to some random value. please suggest me, wat should i do??? do i use some other code instead of ajax for that field? or .... something else...???
  16. lets suppose i am on index page then load 1.php in index page through ajax and there are some links on 1.php i want to open these link also in index page ....
  17. i'm trying to call a php file using ajax and it seems to be returning false, but i have no idea why. any ideas? <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <form method="get" action="test.php"> <input id="myvar" type="hidden" name="albumid" /> <button type="submit" id="btnsubmit">Submit</button> </form> <script type="text/javascript"> $('form').submit(function() { $.ajax({ url: "newAlbum.php", data: {albumid: $('#myvar').val()}, success: function(data){ var album = data; $('#myvar').val(album); return true; } }); return false; }); </script> newAlbum.php <?php echo '11'; ?> test.php <?php echo $_GET["albumid"]; ?>
  18. I am building a WordPress website where I want profiles to be displayed directly on the Home page from the Database as members add their profiles. What I have so far is this: If anyone register through the website, their info is stored in a database and their profiles are displayed in a result page. For example: if you use the search form and search for specific member they will display in: http://www.website.com/results/URL (Where results is the page that always display results. Here is the code I have that works just fine: <style> .person_name { font-size:13px; text-align:center; text-transform:uppercase; padding-top:8px; } .person_image { padding:4.2px; border:1px solid #aaa; width:125px; } </style> <?php $state=$_GET['state']; $county=$_GET['county']; $city=$_GET['city']; $zip=$_GET['zip']; /**/ // Make a MySQL Connection mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("user") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT * FROM persons WHERE city='".$city."' OR zip='".$zip."' ORDER BY name") or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<div style='display:inline-block;margin-right:15px;cursor:pointer;' onclick='location=\"http://www.website.com/profile/?id=".str_replace(' ','_',$row["name"])."\"'>"; echo "<div class='person_image'><img src='http://www.website.com/wp-content/uploads/".$row['photo']."' style='' width='125px' /></div>"; echo "<div class='person_name'>".$row['name']."</div>"; echo "</div>"; } /**/ //echo "page for: ".$state." ".$county." ".$city." ".$zip; ?> On my home page and where I want the data to be displayed other than the result page is kinda tricky. I want to be able to only display 6 profiles. I also want to mention that I am using the Execute PHP plugin that helped me display the php in pages. Here is some of my home page code where I want to display those profiles: if ( is_active_sidebar( 'Our Newest Members' ) ) { echo '<div class="Our Newest Members">'; echo '<h4>' . __( 'Our Newest Members', 'themename' ) . '</h4>'; dynamic_sidebar( 'Our Newest Members' ); echo '</div><!-- end .OurNewestMembers -->'; } I am not a code savvy person but always willing to learn and I am also more than happy to answer any follow up questions. Thank you so much for all your help,!!!! John
  19. Hi guys, I'm trying to build the following functionality, but find myself seriously lacking in coding aptitude and knowledge. I'm hoping you guys can help me out. Ultimate goal: Clean search bar in middle of screen with no submit button; typing specific text ex. "test" brings an html/javascript widget from a separate file ex. "test1.html" and includes that content below the search bar all without a refresh. My current solution (and note that the code is retrofitted from a different project that someone else wrote), is an if-then solution, whereby if the text in the input == "test" then the page includes the test1.html file. main.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Testing</title> <script language="javascript" type="text/javascript"> var XMLHttpRequestObject_test = false; var strSend; if (window.XMLHttpRequest) { XMLHttpRequestObject_test = new XMLHttpRequest(); } else if (window.ActiveXObject) { XMLHttpRequestObject_test = new ActiveXObject("Microsoft.XMLHTTP"); } var i; var finished; function test() { if (XMLHttpRequestObject_test) { strSend = "receive.php?"; i = 0; finished = false; while (finished != true) { if (document.input1.elements[i].type == "text") { strSend = strSend + "&" + document.input1.elements[i].name + "=" + document.input1.elements[i].value; } else if (document.input1.elements[i].type == "checkbox") { strSend = strSend + "&" + document.input1.elements[i].name + "=" + document.input1.elements[i].checked; } else if (document.input1.elements[i].type == "hidden") { strSend = strSend + "&" + document.input1.elements[i].name + "=" + document.input1.elements[i].value; } else if (document.input1.elements[i].type == "password") { strSend = strSend + "&" + document.input1.elements[i].name + "=" + document.input1.elements[i].value; } i = i + 1; if (document.input1.elements[i] != "[object HTMLInputElement]") { finished = true; } else { finished = false; } } XMLHttpRequestObject_test.open("GET", strSend); XMLHttpRequestObject_test.onreadystatechange = function () { if (XMLHttpRequestObject_test.readyState == 4 && XMLHttpRequestObject_test.status == 200) { document.getElementById('test').innerHTML = XMLHttpRequestObject_test.responseText; } } XMLHttpRequestObject_test.send(null); } } </script> </head> <body> <form name="input1"> <input name="txt1" type="text" /> </form><br /> <input name="cmd_submit" type="button" value="Submit" onclick="test()" /><br/> <br/> <div id="test"></div> </body> </html> receive.php <?php if($_REQUEST['txt1'] == "test") { include('test1.html'); } else { echo stripslashes($_REQUEST['txt1']); } ?> Test1.html (the content to be included) <?php echo '<script type="text/javascript" src="http://www.gmodules.com/ig/ifr?url=http://hosting.gmodules.com/ig/gadgets/file/100840413740199312943/stock-quotes.xml&up_stockList=%5EIXIC%2C%5EGSPC%2C%5EN225%2C%5EHSI%2C%5ESTI%2C%5EFTSE%2C%5EGDAXI%2C%5EFCHI&up_chart_bool=1&up_font_size=12&up_symbol_bool=0&up_chart_period=0&up_refresh_secs=30&synd=open&w=290&h=300&title=Stock+Quotes&border=%23ffffff%7C3px%2C1px+solid+%23999999&output=js"></script>'; echo '<p class="p1">ONETEST!</p>'; ?> Result after typing "test" into search bar (no quotes) [SEARCH BAR] ONETEST! Very accurate representation of the search bar, I know. But the google widget that I used to test this doesn't show up, only the text. I have tried many variations on trying to echo the javascript such that php doesn't chuck it, but nothing. // I have alternative code that includes the content via ajax without the use of php and it brings the widget in without a problem, however, I have no idea how to make that "search bar - if string == 'test', then, show include" paradigm without php. Thank you in advance, Alex Long time visitor, first time poster
  20. I am creating three dropdown lists from mysql table. The first two lists work, but it seems to have a problem when populating the third list. When I echo the query this is what is send to the mysql table - SELECT DISTINCT `matter_type` FROM `legalpages` WHERE `Claims Hub`= AND `areas`='VEREENIGING'. it seems as if it does not post the value of the 'Claims Hub'. Here is my select_list2.php script <?php require_once('connectvars.php'); // Here add the name of the table and columns that will be used for select lists, in their order // Add null for 'links' if you don`t want to display their data too $table = 'legalpages'; $ar_cols = array('Claims Hub', 'areas', 'matter_type', 'phone'); $preid = 'slo_'; // a prefix used for element's ID, in which Ajax will add <select> $col = $ar_cols[0]; // the variable used for the column that wil be selected $re_html = ''; // will store the returned html code // if there is data sent via POST, with index 'col' and 'wval' if(isset($_POST['col']) && isset($_POST['wval'])) { // set the $col that will be selected and the value for WHERE (delete tags and external spaces in $_POST) $col = trim(strip_tags($_POST['col'])); $wval = "'".trim(strip_tags($_POST['wval']))."'"; } $key = array_search($col, $ar_cols); // get the key associated with the value of $col in $ar_cols $wcol = $key===0 ? $col : $ar_cols[$key-1]; // gets the column for the WHERE clause $_SESSION['ar_cols'][$wcol] = isset($wval) ? $wval : $wcol; // store in SESSION the column and its value for WHERE // gets the next element in $ar_cols (needed in the onchange() function in <select> tag) $last_key = count($ar_cols)-1; $next_col = $key<$last_key ? $ar_cols[$key+1] : ''; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // connect to the MySQL database if (mysqli_connect_errno()) { exit('Connect failed: '. mysqli_connect_error()); } // check connection // sets an array with data of the WHERE condition (column=value) for SELECT query for($i=1; $i<=$key; $i++) { $ar_where[] = '`'.$ar_cols[$i-1].'`='.$_SESSION['ar_cols'][$ar_cols[$i-1]]; } // define a string with the WHERE condition, and then the SELECT query $where = isset($ar_where) ? ' WHERE '. implode($ar_where, ' AND ') : ''; $sql = "SELECT DISTINCT `$col` FROM `$table`".$where; echo $sql; $result = $dbc->query($sql); // perform the query and store the result // if the $result contains at least one row if ($result->num_rows > 0) { // sets the "onchange" event, which is added in <select> tag $onchg = $next_col!==null ? " onchange=\"ajaxReq('$next_col', this.value);\"" : ''; // sets the select tag list (and the first <option>), if it's not the last column if($col!=$ar_cols[$last_key]) $re_html = $col. ': <select name="'. $col. '"'. $onchg. '><option>- - -</option>'; while($row = $result->fetch_assoc()) { // if its the last column, reurns its data, else, adds data in OPTION tags if($col==$ar_cols[$last_key]) $re_html .= '<br/>'. $row[$col]; else $re_html .= '<option value="'. $row[$col]. '">'. $row[$col]. '</option>'; } if($col!=$ar_cols[$last_key]) $re_html .= '</select> '; // ends the Select list } else { $re_html = '0 results'; } $dbc->close(); // if the selected column, $col, is the first column in $ar_cols if($col==$ar_cols[0]) { // adds html code with SPAN (or DIV for last item) where Ajax will add the select dropdown lists // with ID in each SPAN, according to the columns added in $ar_cols for($i=1; $i<count($ar_cols); $i++) { if($ar_cols[$i]===null) continue; if($i==$last_key) $re_html .= '<div id="'. $preid.$ar_cols[$i]. '"> </div>'; else $re_html .= '<span id="'. $preid.$ar_cols[$i]. '"> </span>'; } // adds the columns in JS (used in removeLists() to remove the next displayed lists when makes other selects) $re_html .= '<script type="text/javascript">var ar_cols = '.json_encode($ar_cols).'; var preid = "'. $preid. '";</script>'; } else echo $re_html; ?> I am also using this ajax script which access the above script. // function used to remove the next lists already displayed when it chooses other options function removeLists(colid) { var z = 0; // removes data in elements with the id stored in the "ar_cols" variable // starting with the element with the id value passed in colid for(var i=1; i<ar_cols.length; i++) { if(ar_cols[i]==null) continue; if(ar_cols[i]==colid) z = 1; if(z==1) document.getElementById(preid+ar_cols[i]).innerHTML = ''; } } // create the XMLHttpRequest object, according browser function get_XmlHttp() { // create the variable that will contain the instance of the XMLHttpRequest object (initially with null value) var xmlHttp = null; if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } // for Forefox, IE7+, Opera, Safari else if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } // IE5 or 6 return xmlHttp; } // sends data to a php file, via POST, and displays the received answer function ajaxReq(col, wval) { removeLists(col); // removes the already next selects displayed // if the value of wval is not '- - -' and '' (the first option) if(wval!='- - -' && wval!='') { var request = get_XmlHttp(); // call the function with the XMLHttpRequest instance var php_file = 'select_list2.php'; // path and name of the php file // create pairs index=value with data that must be sent to server var data_send = 'col='+col+'&wval='+wval; request.open("POST", php_file, true); // set the request document.getElementById(preid+col).innerHTML = 'Loadding...'; // display a loading notification // adds a header to tell the PHP script to recognize the data as is sent via POST request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.send(data_send); // calls the send() method with data_send // Check request status // If the response is received completely, will be added into the tag with id value of "col" request.onreadystatechange = function() { if (request.readyState==4) { document.getElementById(preid+col).innerHTML = request.responseText; } } } } where did i miss something?
  21. I am going crazy with my ajax calls. I have finally discovered the issue, but tried numerous ways to fix it with no avail. So essentially I have an ajax call from different levels in the site, there could be from 1 to 4 different directories in the url of the site, which is what causes the issues. function add_cart(pid,quantity) { $.ajax({ type : 'POST', url : '../../ajax/add-cart.php', data : 'pid='+pid+'&quantity='+quantity, success : function() {} }); } I have tried changing the path to http://www.mydomain.com/ajax/add-cart.php, /ajax/add-cart.php, document.location.origin+"/ajax/add-cart.php", "//www.mydomain.com/ajax/add-cart.php" But nothing is working. I am sure I am not the first person to run into this issue, so what is the answer?
  22. Hello, I am working on piece of code and now I am figuring out a way to complete it. I am merging ajax+PHP+ MySQL, what I am trying to do is fetch data using ajax on same page and data will be shared between 3 <select> tags In first <select> tag, I have listed All the "managers" working in company, when I click on any "manager" name, second <select> must show the "assistant manager" , after clicking on "assistant manager" <select>, it must show "team leaders" name in 3rd <select>, and after clicking on "team leader name" <select>, all the staff must display on the 4th <select>. I am able to fetch the records of manager and "assistant manager", but I am unable to proceed further. Can anyone help me ??? I have attached the sample view of the code that I am trying to complete, have a look and let me know the solution, you may also email it on pawan2angel@gmail.com....please do have a look on attachment........ code.html
  23. Hello, I have piece of code I have written that, when the form is submitted it sends the string from the textbox through ajax, through a database and returns a name corresponding to that string. It works fine in chrome but not in firefox and I was wondering if you could help. If I set the function to a simple alert(code) it will fire it and work fine however when I revert it to the ajax script it simply reloads the page with the "?code=string" and ignores anything and everything in the js function. This is the ajax code: function signin(code) { // event.preventDefault(); var xmlhttp; var photo; if (code=="") { document.getElementById("resultcontents").innerHTML="lol"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var str = xmlhttp.responseText; var split = str.split(", "); document.getElementById("resultcontents").innerHTML=split['0']; document.getElementById("counter").innerHTML=split['1']; if(!(split['2'] == undefined)){ document.getElementById("webcamcanvas").innerHTML="<img src='" +split['2']+"' width='400' height='300'>"; } document.getElementById("codetextbox").value=""; document.getElementById("codetextbox").focus(); } } xmlhttp.open("GET","files/******.php?code="+code,true); xmlhttp.send(); } This is the HTML form: form onsubmit="signin(codeform.codetextbox.value)" name="codeform"> <input type="textbox" name="codetextbox" id="codetextbox" /> </form> The reason it has no submit button is because firstly, it clutters up the page and secondly I'm using a barcode scanner which automatically inserts a carriage return, submitting the form. Any help would be greatly appreciated! Also, I'm sorry if this is in the wrong section, it's to do with both JS and Ajax and I didn't know which to choose. Jacbey.
  24. I have 2 sites on my machine, one is my development site and one is third party site. The third party site has a aspx file that returns information. I have been trying access this through Jquery and Ajax but ran into a cross domain problem. Am I right in thinking I can do this is PHP? and are their any simple tutorials that someone could point me to. thanks Jasemilly
  25. hi guys, im new with google map, i need some help. i have ajax call, here: $('#checkbtn').click(function(e) { e.preventDefault(); var lo=$("#long").val(); var la=$('#lat').val(); $.ajax({ url:BASEURL+'register/checklocation', type:'POST', data:{log:lo,lat:la}, success:function(data) { $('#view_checkmap').html(data); } }); }); here is my view to view the map: <script> function initialize() { var myLatlng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>); var mapOptions = { zoom: 15, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById('mymap'), mapOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: 'my location' }); } google.maps.event.addDomListener(window, 'load', initialize); </script> <div id="mymap" style="width:500px; height:300px;"></div> when i access to the URL, it displays, but when i access over ajax, nothing display. is my code worng or something else? thanks in advance.
×
×
  • 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.