JavaScript - Simple Mysql Query Needed For Newbie
Not new to programming but I am to JQuery (and j/script in general).
I need to query a mysql database to return a small amount of data (some text) based on a user code (e.g. MrABC). I could use an iFrame and PHP but if the internet connection is down I do not want error messages displayed - the intended audience have limited cognitive capabilities and will not cope with ERROR 404 etc... Essentially I need to be able to create a function that can be called with a parameter of the usercode and which returns the text from the lookup. What I put in the function is a complete mystery to me ... Similar TutorialsI have the following code to load iframes but I don't know how to make it load the "LT-video_default.html" when it first loads the page. If I choose one of the options and then go back and choose the "Choose a manufacturer" option it loads the desired page. Here is the code. Code: <script language="JavaScript"> <!-- Begin function leapto(form) { var myindex=form.dest.selectedIndex parent.CONTENT.location.href=(form.dest.options[myindex].value); // You can output to ANY frame using: parent.[framename].location.href } // End --> </script> <div id="videoWrapper"> <form name="labtv"> <select name="dest" size="1" onchange="leapto(this.form)"> <option selected="selected" value="LT-video_default.html">Choose A Manufacturer </option><option value="LT-video_nanodrop.html">NanoDrop </option><option value="LT-video_bioflux.html">Bioflux </option><option value="LT-video_genvault.html">GenVault </option><option value="LT-video_hamilton.html">Hamilton </option></select> </form> <iframe name="CONTENT" frameborder="no" height="400" scrolling="no" width="650"> </iframe> </div> Folks I am a newbie to JavaScript. I am basically java/j2ee developer . I want to learn javascript and Ajax . So please let me know what is the latest version of JavaScript , also let me know what book I have to buy ( I mean for the newbie ) Please help me . Thanks in Advance Hey Coding Forum, Hey as you probably know iam new here as i probably haven't even posted this in the correct place but i have a real problem with my JavaScript and i can't get it to do what i would like. I have to write a code to show a new array to represent the third row of a table (var myarray value of which are "60","80","187","180","114" , and creating an array of the required length. Which i have done. (i Think ) I now need to write the remainder of the JavaScript needed to calculate the average height of the objects and write it out in the browser window. It need to write average height 17.2 cm. I have included my script below and but i am not understanding how to work out the average, i believe i need to add another 'for loop' but i can't get it to work correctly. (i might be being completely stupid) If anyone would be able to help it would be GREATLY appreciated. Thanks for all help. <HTML> <HEAD> <TITLE> Test Experiment </TITLE> <SCRIPT LANGUAGE = "JavaScript"> var height = [15,16,17,18,19]; var number = [4,5,11,10,6]; var myarray = new Array(5) var myarray = ["60","80","187","180","114"] ; var values = [60, 80, 187, 180, 114]; var total = 0; for ( var i = 0; i < values.length; ++i ) { total += values[i]; } var myarray = total + values.length; document.write('average height of the object is ' +myarray + '<br>'); </SCRIPT> </HEAD> <BODY> </BODY> </HTML> I'm trying to render 14 same sized images on a webpage using a Javascript, I've used in the past, but now can't seem to get it to work. Getting a Syntax Error. On Page http://www.newenglandonline.net/index.fix.html The ERROR appears to be on the following; line 270: var imageDir = ; [CODE] <script type="text/javascript"> (function() { var rotator = document.getElementById(rotator); var imageDir = ; var delayInSeconds = 3; var images = [Cannon_top.jpg,Mount-Washington-Summer.jpg,Mount-Washington-Winter.jpg,Boston_Charles.jpg,Boston_Harbor.jpg,Boston_Harbor_night.jpg,Zakim Bridge.jpg,Edgartown.jpg,GayHeadLighthouse.jpg,HighlandLight.jpg,Newport.jpg,Bridgeport.jpg,Eastpoin tLight.jpg]; var num = 0; var changeImage = function() { var len = images.length; rotator.src = imageDir + images[num++]; if (num == len) { num = 0; } }; setInterval(changeImage, delayInSeconds * 1000); })(); </script> [CODE] Any help or insight will be greatly appreciated. Thanks in advance. hi i am trying to populate a textarea with the selections like checkboxes radiobuttons textbox combobox but i cant seem to do so. i am naive to the field of programing, and found a few code snippets to do so i tried but it did no good... help needed this is my code " <html> <head> <style type="text/css"> .minitext { font: normal 0.7em Arial, sans-serif; color: Black; } .disable { background-color: #CF110C; color: #fff; font-weight: bold; padding: 5px; } </style> <script language="Javascript" type="text/javascript"> function populateTextArea(){ var output = new Array(); var fieldID = 1; while (fieldObj = document.MyForm['iid'+fieldID]) { if (fieldObj.length) { for (var j=0; j<fieldObj.length; j++) { if (fieldObj[j].checked) { output[output.length] = fieldObj[j].value;} }//end of for } //end of if else { if (fieldObj.checked) { output[output.length] = fieldObj.value; } }//end of else fieldID++; }// end of while document.getElementById('targetarea').value = output.join(', '); //document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value ; } </script> </head> <body> <br> <br> <form name="MyForm" method="POST" action="#"> String 1: <input type="text" name="ip1" value=""><br> String 2: <input type="text" name="ip2" value=""><br> String 3: <input type="text" name="ip3" value=""><br><br> <input type="checkbox" name="iid1" id="pe_item2" value="Text string 1"> Text string <input type="checkbox" name="iid1" id="pe_item2" value="Text string 12"> Text string 1<br><br><br> <input type="radio" name="iid2" id="pe_item4" value="Text string 2">Text string 2 <input type="radio" name="iid2" id="pe_item6" value="Text string 3">Text string 3<br> <input type="radio" name="iid3" id="pe_item8" value="Text string 4">Text string 4 <input type="radio" name="iid3" id="pe_item10" value="Text string 5">Text string 5<br> <input type="radio" name="iid4" id="pe_item12" value="Text string 6">Text string 6 <input type="radio" name="iid4" id="pe_item14" value="Text string 7">Text string 7<br> <br> <br> <a href="#" onClick="document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value + populateTextArea();" >Populate</a><br> <br> <INPUT TYPE=BUTTON VALUE="Co" ONCLICK= populateTextArea(); > <br> <textarea id="targetarea" name ="targetarea" cols="50" rows="5"></textarea> </form> </body> </html> " help need this done urgently I have yet to have my ah-ha moment with Javascript but I think its coming soon. there are small things that seem to be baffling me and Im hoping posting to the forums to get help from people of limitless wisdom. What exactly does the "|" mean in this code? or I should say what does it do? Code: document.template.Aprod_string.value = document.template.Aprod_string.value + "|" + string_recode(Aprod_array) ; Lets say I have two images in a box Code: <body> <div id="box"> <img src="image1.jpg" id="image1" width="100" height="100" /> <img src="image2.jpg" id="image2" width="100" height="100" /> </div> </body> When I click on Image1 I want Image2 to get replaced with a new image, called Image3. So I tried this code: Code: var image1 = document.getElementById("image1"); image1.onclick = image1_click (); function image1_click () { new_image= new Image new_image = document.getElementById("image2"); new_image.src="image3.jpg" } But instead of replacing the image on click, from some reason it replaces image2 with image3 from start/load. What should I do to make this work? Thank you. I have a page with options, and I need to hide options unless a certain choice is selected. So say you have a select box for male and female, if they select male, I need it to show male options, and if they select female, it shows female options. How can I hide things until selected and then show the textboxes and stuff? Thank you! I'm in search for a simple and clean timed rotation script. I have these quotes, and right now they're coded so that a single quote displays and changes upon refresh. The script is really clean, and I would like to maintain the cleanliness but make the images rotate every couple of seconds. Here's the script... Code: <script type="text/javascript"> quote = new Array(3); quote[0] = "Quote 1"; quote[1] = "Quote 2"; quote[2] = "Quote 3"; index = Math.floor(Math.random() * quote.length); document.write(quote[index]); </script> It's probably a really simple piece of coding, but I'm still new to JavaScript, so it's obviously out of my range. I appreciate anyone who will help Hi Coders... I'm building a 'really simple' JavaScript program to help editors write SEO-friendly META titles and META descriptions. The idea is you have 3 text boxes, each on a separate line: BOX 1 - META TITLE [ i.e. "Cool website page" ] BOX 2 - FILE NAME [ i.e. "This is a really cool web page about cool stuff"] BOX 3 - META DESCRIPTION [ i.e. "cool-web-page" ] As the editor types in the boxes, a serp listing is displayed as it would appear on Google (and ideally how it would appear on Bing and Yahoo): Cool website page www.coolwebsite.com/cool-web-page This is a really cool web page about cool stuff Kudos to any one who could point a JavaScript newbie in the right direction in excel i want to replace the word bebo with a value in cell B1 this is the line CREATE TABLE IF NOT EXISTS `bebo` ( `id` int(10) NOT NULL auto_increment,`beboid` varchar(255) default '0',`status` varchar(255) default 'No Comment Posted',PRIMARY KEY (`id`)) in column B i have a load of values so i need an excel formula to replace bebo so that it will take values from B1 to B26 any ideas please? I know this is not the correct section to be posting in but couldnt find a relative section on this site.. Thanks for your help I'm looking to find a script... My client wants his users to be able to enter their zip code into a "check coverage area" text box. Then, on submit, it should return a message saying whether zip code is covered by his business. It seems like this would be a simple (ish) "if-else" script, listing the covered zip codes, but I'm not very experienced in javascript. Can anyone direct me to a free or cheap script that I could use and adapt for this? Thanks soooo much. I found a menu I really like at the top of the page at www-dot-sachscreative-dot-com but can't figure out how it works from the source code. Can someone tell me how to make something like it which is browser independent and uses javascript and/or CSS? It's been years since I did javascript work and I've forgotten must of what I used to know. Thanks.
Hello all, As I am new to java scripts, I usually solve thing with trial and error. What I need is a very simple java script for a count down timer, after searching here I found this: ---------------------- Code: <font style="font-size:72px" color="#FF0000" face="Arial"> <script type = "text/javascript"> var page = "http://www.google.com"; //The page to redirect to function getSeconds() { startTimer (3); // 36 hours } var timeInSecs; var ticker; function startTimer(secs){ timeInSecs = parseInt(secs); ticker = setInterval("tick()",1000); tick(); // to start counter display right away } function tick() { var secs = timeInSecs; if (secs>0) { timeInSecs--; } else { window.location = page; // stop counting at zero // and start again if required } var hours= Math.floor(secs/3600); secs %= 3600; var mins = Math.floor(secs/60); secs %= 60; var result = ( (mins < 10) ? "0" : "" ) + mins + ":" + ( (secs < 10) ? "0" : "" ) + secs; document.getElementById("countdown").innerHTML = result; } </script> <body onload = "getSeconds()"> <span id="countdown" style="font-weight: bold;" ></span> ----------------------------- I modified some stuff, as I defined the font face and size, the color as well, and I added a var to open a certain page when the time is over (as I said before, all these modifications came right with trial and error). So, is that script good? or are there better scripts that do the same job? And, can someone please provide me with a script that does the same functionality of the script I mentioned but instead of showing digits it shows: 01 minutes 31 seconds ? Thank you so much. I have a simple validation script. The first line of the validation is: function Validate() { if (document.form.name.value == '') { the id of my form is form, so my query is will this validation work, as it does not have a name but it has an id. Should I change the name (above) to id? Hello I'm trying to create a graph that will accept 1 or multiple data sets depending on what the user selects. How can I add get the data into the graph using a loop? I want it to add a line for each selection. Thanks // Graph Data ############################################## var graphData = [{ // Visits data : <?php echo '['.implode($data).'],'?> color: '#71c73e' }, { // Visits data : <?php echo '['.implode($data_1).'],'?> color: '#red' }, ]; First off, I'd like to say that I do not know much javascript. I am building a rather intensive website for tutorial purposes, and so far it has required me to become quite familiar with html5, css, php, and mysql. However, I've avoided javascript like the plague due to how different it seems from the rest. Lets just say, I'm confused. I've scoured the net looking for a similar tutorial on how to create a pop-up window onclick for a link. This is what I currently have it doing: Firstly, I query and display the DB, referencing images based on an incremental variable. I really want to make it all automatic...in the sense, that when I update the database with a new "Structure" it will automatically apply itself to the page without me having to edit html/css/js/php/etc. It all seems to be working fine, except when I click on the second listing. It refers to the same div (Town Center), because, I assume, the divs are identically labeled, and it refers to the first. Here is my code: This is my Callstructures.php file. Code: <?php $query = "SELECT str_name, str_imageloc, str_infoloc FROM structures"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $i = 0; if (mysql_num_rows($result) > 0) { while(list($str_name, $str_imageloc, $str_infoloc) = mysql_fetch_row($result)) { echo "<li>"; echo "<a href='#' onClick='javascript: loadPopup()';>"; echo "<img src='$str_imageloc' title='$str_name' longdesc='$str_infoloc' alt='stralt text' class='image$i'>"; echo "</a>"; echo "</li>"; echo "<div id='popupContact'>"; include ($str_infoloc); echo "</div>"; $i++; } } ?> This is my main page: Structures.php Code: <body> <div id =allstr> <ul> <?php include 'gamephp/callstructures.php'; ?> </ul> <div id="backgroundPopup"></div> </div> </body> </div> </html> And here is the JavaScript I am using, popup.js: Code: /***************************/ //@Author: Adrian "yEnS" Mato Gondelle //@website: www.yensdesign.com //@email: yensamg@gmail.com //@license: Feel free to use it, but keep this credits please! /***************************/ //SETTING UP OUR POPUP //0 means disabled; 1 means enabled; var popupStatus = 0; //loading popup with jQuery magic! function loadPopup(){ //loads popup only if it is disabled if(popupStatus==0){ $("#backgroundPopup").css({ "opacity": "0.7" }); $("#backgroundPopup").fadeIn("slow"); $("#popupContact").fadeIn("slow"); popupStatus = 1; } } //disabling popup with jQuery magic! function disablePopup(){ //disables popup only if it is enabled if(popupStatus==1){ $("#backgroundPopup").fadeOut("slow"); $("#popupContact").fadeOut("slow"); popupStatus = 0; } } //centering popup function centerPopup(){ //request data for centering var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#popupContact").height(); var popupWidth = $("#popupContact").width(); //centering $("#popupContact").css({ "position": "absolute", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2 }); //only need force for IE6 $("#backgroundPopup").css({ "height": windowHeight }); } //CONTROLLING EVENTS IN jQuery $(document).ready(function(){ //LOADING POPUP //Click the button event! $("#button").click(function(){ centerPopup(); loadPopup(); }); //CLOSING POPUP //Click the x event! $("#popupContactClose").click(function(){ disablePopup(); }); //Click out event! $("#backgroundPopup").click(function(){ disablePopup(); }); //Press Escape event! $(document).keypress(function(e){ if(e.keyCode==27 && popupStatus==1){ disablePopup(); } }); }); And the CSS for the popup: Code: /* pop up css */ html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { border:0pt none; font-family:inherit; font-size:100%; font-style:inherit; font-weight:inherit; margin:0pt; padding:0pt; vertical-align:baseline; } body{ background:#fff none repeat scroll 0%; line-height:1; font-size: 12px; font-family:arial,sans-serif; margin:0pt; height:100%; } table { border-collapse:separate; border-spacing:0pt; } caption, th, td { font-weight:normal; text-align:left; } blockquote:before, blockquote:after, q:before, q:after { content:""; } blockquote, q { quotes:"" ""; } a{ cursor: pointer; text-decoration:none; } br.both{ clear:both; } #backgroundPopup{ display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:100%; width:100%; top:0; left:0; background:#000000; border:1px solid #cecece; z-index:1; } #popupContact{ display:none; position:fixed; _position:absolute; /* hack for internet explorer 6*/ height:384px; width:408px; background:#FFFFFF; border:2px solid #cecece; z-index:2; padding:12px; font-size:13px; } #popupContact h1{ text-align:left; color:#6FA5FD; font-size:22px; font-weight:700; border-bottom:1px dotted #D3D3D3; padding-bottom:2px; margin-bottom:20px; } #popupContactClose{ font-size:14px; line-height:14px; right:6px; top:4px; position:absolute; color:#6fa5fd; font-weight:700; display:block; } #button{ text-align:center; margin:100px; } Should I keep this code? Is there anyway to make it work? My thought process is to change "callstructures" to include a variable ($i is already there) that creates a bunch of unique div ids Code: echo "<div id='popupContact$i'>"; Then in the JS, somehow alter it so it recognizes the change. If not, are there any tips, or possible links to tutorials and info on how I can figure this out. With much appreciation, Thanks! I want to use a database query to grab all of a member's friends from a table in order to add the friend's email address to a form, to ready it for POSTing. I am using the jquery ui, so on my form.php page, I have the script and html: Code: <script> $(function() { $( "#friendsearch" ).autocomplete({ source: "search.php", minLength: 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.id + " " + ui.item.value : "Nothing selected, input was " + this.value ); } }); }); </script> <form>... <input id="friendsearch" /> </form> And on my search.php I have: Code: //code to connect to database.... etc $query = " //this code goes through a table LEFT JOIN to grab a list of the logged-in member's friends' info (id, email, first name, last name) " $sql = mysql_query($query); while($row = mysql_fetch_array($sql)) { $fid = $row["id"]; $firstname = $row["firstname"]; $lastname = $row["lastname"]; $email = $row["email"]; echo $fid <br /> $f_firstname <br /> $f_lastname <br /> $email <br /> "; The "echo" above works. It lists out all the info perfectly, so I know my query is good. The problem, I am having, is with what comes next in the search.php: Code: $q = strtolower($_GET["term"]); // supposed to do something with $q here (not sure what!) $return = array(); while ($row = mysql_fetch_array($query)) { array_push($return,array('id'=>$row['firstname'],'value'=>$row['lastname'])); } echo(json_encode($return)); This is the part that's suppose to work with the jquery autocomplete. I know it's wrong, but I need to know how I can fix it to do the following: 1) when the user starts typing the first name or last name of the friend, auto-complete shows a drop-down list of firstname lastname. 2) once the friends' names are placed in the input box, on submit, i want to POST the friends' email addresses (not their name)! Complex, I know... Any help would be much appreciated! Thanks, June |