JavaScript - Best Way To Pass A Variable Dynmically
I'm trying to overcome one feat, and I've just ran the course of my little knowledge of javascript. Here is the code that concerns us.
Code: function loadXMLDoc() { 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) { populateParentWindow(xmlhttp.responseText); } } xmlhttp.open("GET","https://www.syncupsolutions.net/currentdirectory-<?php echo $_COOKIE['User'] ?>.txt",true); xmlhttp.send(); } function populateParentWindow(Directory) { $("#FTPContents").load('functions/testftp.php?HASH=' + Get_Cookie("ftphash") + "&reload=" + Directory) ; }; $(function(){ $('#swfupload-control').swfupload({ upload_url: 'functions/upload-file.php?UID=' + Get_Cookie("User"), file_post_name: 'uploadfile', file_size_limit : "10000", file_types : "*.*", file_types_description : "All Files", file_upload_limit : 5, flash_url : "functions/js/swfupload/swfupload.swf", button_image_url : 'functions/js/swfupload/wdp_buttons_upload_114x29.png', button_width : 114, button_height : 29, button_placeholder : $('#button')[0], debug: false }) .bind('fileQueued', function(event, file){ var listitem='<li id="'+file.id+'" >'+ 'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+ '<div class="progressbar" ><div class="progress" ></div></div>'+ '<p class="status" >Pending</p>'+ '<span class="cancel" > </span>'+ '</li>'; $('#log').append(listitem); $('li#'+file.id+' .cancel').bind('click', function(){ var swfu = $.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); $('li#'+file.id).slideUp('fast'); }); // start the upload since it's queued $(this).swfupload('startUpload'); }) .bind('fileQueueError', function(event, file, errorCode, message){ alert('Size of the file '+file.name+' is greater than limit'); }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); }) .bind('uploadStart', function(event, file){ $('#log li#'+file.id).find('p.status').text('Uploading...'); $('#log li#'+file.id).find('span.progressvalue').text('0%'); $('#log li#'+file.id).find('span.cancel').show(); }) .bind('uploadProgress', function(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); }) .bind('uploadSuccess', function(event, file, serverData){ var item=$('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); var pathtofile='<a href="uploads/'+file.name+'" rel="nofollow" target="_blank" >view »</a>'; item.addClass('success').find('p.status').html('Done!!! | '+pathtofile); }) .bind('uploadComplete', function(event, file){ // upload has completed, try the next one in the queue $(this).swfupload('startUpload'); loadXMLDoc(); }) You'll notice at the beginning, the functino loadXMLDoc. This function GETS the contents of a text file, which is the path to the directory the user is browsing. The next function is populateParentWindow. This is the function that dynamically updates the div that displays the files and folders of the current directory so they can see their file has been uploaded. Scroll down a little further and you'll see my problem. Code: $(function(){ $('#swfupload-control').swfupload({ upload_url: 'functions/upload-file.php?UID=' + Get_Cookie("User"), At the bottom of the above line, the : upload_url, I need it to contain the contents of the text file also, but in a POST value, like the UID, something like, directory=thedirectory. But, when I try Code: $(function(){ $('#swfupload-control').swfupload({ upload_url: 'functions/upload-file.php?UID=' + Get_Cookie("User") + "&directory=" + xmlhttp.responseText, It gives me an undefined, right off the bat before any uploading, or anything at all takes place. I'm guessing this is because this value is set on page load, and not before the actual upload actually happens. Does anyone have any ideas how I can set this value when the upload begins with the variable from the text file ? Keep in mind it has to be inside the function it's in now or it wont work. Note that the loadXMLDocument function isn't called until the upload is complete, the .bind at the bottom of the page. I've tried pulling it from the text file several ways, setting the document.title to the current directory and calling it in the function, it just always seems a step behind me or undefined. Any ideas ? Similar TutorialsHi!! I am trying to find out solution for this since long. I tried js but as I am not good with it, I just want to do this through PHP. I am adding dynamic rows when user clicks the Add Row button.I want to show the calculated amount like: line_total=qty*unit_price; PHP Code: if (isset($_POST['qty']) && sizeof($_POST['qty']) > 0) { for($i = 0, $maxi = count($_POST['qty']); $i < $maxi; $i++) { $quantity = (isset($_POST['qty'][$i]) && !empty($_POST['qty'][$i])) ? mysql_real_escape_string($_POST['qty'][$i]) : 0; $description = (isset($_POST['description'][$i]) && !empty($_POST['description'][$i])) ? mysql_real_escape_string($_POST['description'][$i]) : 0; $unit_price = (isset($_POST['unit_price'][$i]) && !empty($_POST['unit_price'][$i])) ? mysql_real_escape_string($_POST['unit_price'][$i]) : 0; $line_total = (isset($_POST['line_total'][$i]) && !empty($_POST['line_total'][$i])) ? mysql_real_escape_string($_POST['line_total'][$i]) : 0; ?> <?php $myvar=$quantity*$unit_price; ?> <script type="text/javascript"> jsvar = <?php echo $myvar; ?>; document.write(jsvar); // Test to see if its prints array: </script> } } This code works very well and displays the values.But if I use it in the function like; PHP Code: function line(elem) { jsvar = <?php echo $myvar; ?>; document.getElementById("line_total").value = jsvar; } And call it: PHP Code: <input type="text" name="line_total[]" id="line_total" onBlur="return line(this)"> It is not showing the result. Kindly guide me where I am going wrong? This is my function to add rows: PHP Code: <script type="text/javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if(rowCount<3) { var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; //alert(newcell.childNodes); switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } else { alert("Maximum Limit Of 3 Rows Reached"); } } </script> Please help me I've avoided cookies for 12 years. I made my first cookie today: Code: <p><a href="projects.html" onclick="document.cookie='whichPic=8'">Set Cookie</a></p> I have an external javascript sheet with an array of images w/text and the following code: Code: var current = 0; function update() { var pic = slides[current]; document.getElementById('proj_title').innerHTML = pic.title; document.getElementById('proj_image').src = "images/slides/" + pic.image; document.getElementById('proj_location').innerHTML = "<span>Location:</span> " + pic.location; document.getElementById('proj_operation').innerHTML = "<span>Commercial Operation:</span> " + pic.commercial_operation; document.getElementById('counter').innerHTML = (current + 1) + " of " + slides.length; if(pic.link) { document.getElementById('proj_link').style.display = "block"; document.getElementById('proj_href').href = pic.link; } else { document.getElementById('proj_link').style.display = "none"; } } When the user clicks the link, it should open the page to the slideshow and it should start on slide[8]. I think what I need to do is pass the value of the cookie to the variable "current", but I don't know how to do that. Also, I only need the cookie to last long enough for the new page to load (about 20 seconds), but all of the cookie scripts I've found set expiration in days. Any guidance would be appreciated. Hey I have a JS value but it won't put the value in the brackets when i try to get the element by ID instead it is looking for the id named the same as the variable name. Here is what i got to explain better: Code: function fill_div(v) { document.getElementById(v).innerHTML="<img src='untitle.png' style='width:100%;height:100%;'/>"; } var x = 0; var y = 3; var area = 1; window.onload = fill_div(area+':'+x+':'+y); It ends up looking for id v instead of id 1:0:3. Any idea how i correct this ? Hi all, I need to pass a variable to an inner function and I got it to work but: (1) I don't know why it works (2) I don't know if it's right or optimal So, please look and comment: Code: for (var h = 1.0; h <= 3.0; h += 0.5) { ed.settings.formats['spacing' + String(h.toFixed(1))] = { 'block' : 'p', 'styles' : { 'marginBottom' : String((h - 1).toFixed(1)) + 'em' } } h = (function (h) { c.onRenderMenu.add(function (c, m) { m.add({ 'title': String(h.toFixed(1)), 'caption' : 'Set the line spacing to ' + String(h.toFixed(1)), 'onclick': function () { ed.formatter.apply('spacing' + this.title); return false; } }).setDisabled(false); }); return h; })(h); }; You can ignore a lot of the code as it doesn't factor into the question... and I know that re-ordering the code can eliminate my problem (but I can't re-order it because defining the formats MUST come before "renderMenu" or else it doesn't work - and I don't want to use two loops - one to define the formats and another to define the menu). The part that's freaking me out is this: Code: h = (function (h) { c.onRenderMenu.add(function (c, m) { m.add({ 'title': String(h.toFixed(1)), 'caption' : 'Set the line spacing to ' + String(h.toFixed(1)), 'onclick': function () { ed.formatter.apply('spacing' + this.title); return false; } }).setDisabled(false); }); return h; })(h); See the strange things I have to do to get h inside of c.onRenderMenu.add()? Is this right? Can I do it any "better" or more correctly? Thanks! -- Roger Hello. I am very new at using javascript and jquery. Right now Im working on a website, and it has a hierarchical menu in the right and im also doing some content loading in a div, all that with javascript. My problem is that when they click on a link, I need to pass a variable "id" through the link. I dont want to pass it in the url, but I want to pass it in another way, for every link the id is going to be different. How can I pass a variable to another page and how can I retrieve it in that page so I can use it for the content loading? Thanks! I'm trying to echo a php variable to my javascript function but nothing is happening Basically this php page displays bunch of records with a radio button next to each record. So when the radio button is clicked it would open that record in a new window that is clicked. Code: <input type='radio' name='option' value='$ctr' id='$ctr' onClick="edit_record('<?php echo $ctr ?>')"> <script type="text/javascript"> function edit_record(){ var value = arguements[0]; alert("record id: " + value); window.open("Edit.php", "Edit Record", "status=1, height=400, width=900, resizable=0"); } i am trying to pass the a variable "oneone" from a select box to a php page via java script. this is my html Code: <div id="wrapper"> <div id="content"> <form> Select a Customer: <select id="oneone" name="oneone" value=""> <option value="s_last">last</option> <option value="s_first ">first</option> <option value="c_city">cirty</option> </select> </form> <div> <form method="get" action="" class="asholder"> <small style="float:right">Hidden ID Field: <input type="text" id="testid" value="" style="font-size: 10px; width: 20px;" disabled="disabled" /></small> <label for="testinput">Person</label> <input style="width: 200px" type="text" id="testinput" value="" /> <input type="submit" value="submit" /> </form> </div> </div> this is my javascript Code: <script type="text/javascript"> var options = { script:"test.php?json=true&limit=6&", varname:"input", json:true, shownoresults:false, maxresults:6, callback: function (obj) { document.getElementById('testid').value = obj.id; } }; var as_json = new bsn.AutoSuggest('testinput', options); var optionsa = { script:"test.php?", varname:"one", json:false }; var as_jsona = new bsn.AutoSuggest('oneone', optionsa); </script> and the little part of my php Code: $input =$_GET['input']; $q =$_GET["one"]; can someone PLEASE tell my why i cant get this to work!!! Here's something that I tested without the PHP and it worked ok. Now that I've introduced the PHP to the document it doesn't work. The PHP variable is not passing to Javascript properly. By use of some cleverly placed alert boxes, I figured out that the only thing that is getting passed forward is something called : "object HTML ImageElement" Specifically, I assign the element ID the unique ID number of the record in the SQL database. The problem isn't with the ID numbers themselves: They are alphanumeric and unique. I think it boils down to one of two lines of code. Either this isn't working (about line 12) Code: function expander(RecordID){ or perhaps it is when I am calling the function (about line 66): Code: echo "<img id='".$row['IDNumber']."' src=".$row['ImagePath']." width='5%' onMouseOver='expander(".$row['IDNumber'].");' onMouseOut='shrinker(".$row['IDNumber'].");'>";} The PHP works (I can get the images to appear, so the connection to SQL and such isn't a problem). I am sure most of the JavaScript is good, too, as I said I had it all working prior to dropping in the PHP. Since I am not going from JavaScript to PHP I don't think I need AJAX. I just need the PHP to pass to JavaScript. Any ideas? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="class.css" /> <script type = "text/javascript" language="javascript"> //<![CDATA[ var maxheight = 150; var countShrink = 1; function expander(RecordID){ var countGrow = 1; var pic = document.getElementById(RecordID); if(pic){ var imageh = pic.height; var imagew = pic.width; if(imageh<100){ countGrow++; imageh = imageh*1.2; imagew = imagew*1.2; pic.style.height = imageh + "px"; pic.style.width = imagew + "px"; var timer = window.setTimeout(function(){expander(RecordID);},2);} } else {alert("error on");} } function shrinker(RecordID){ var pic = document.getElementById(RecordID); if(pic){var counter = 1 var imageh = pic.height; var imagew = pic.width; if(imageh>20){ imageh = imageh/1.2; imagew = imagew/1.2; pic.style.height = imageh + "px"; pic.style.width = imagew + "px"; var timer = window.setTimeout(function(){shrinker(RecordID);},3);} } else {alert("error off");} } //]]> </script> </head> <body> <?php include('menuSub.html'); require_once('connect.php'); $idnum = 'phmdv06tbu'; //$q="SELECT * FROM art WHERE IDNumber = '".$idnum."'"; $q="SELECT * FROM art ORDER BY IDNumber LIMIT 4"; $r = @mysqli_query ($dbc, $q); echo "<div class='bodyContent'><div class='imageContent'>"; if($r){ while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){ echo "<img id='".$row['IDNumber']."' src=".$row['ImagePath']." width='5%' onMouseOver='expander(".$row['IDNumber'].");' onMouseOut='shrinker(".$row['IDNumber'].");'>";} } else{ echo '<div class="bodyContent"> Error<div>'; } echo "</div></div>"; mysqli_close($dbc); ?> </body> </html> hi guys! i have a problem in passing the variable to function ,the variable which is used in<td> as table data. Code: <td onmouseover="todayevent(somevarible);" onmouseout="hideevent(somevarible);" >' + somevarible+ '</td> i want to pass somevariable by function todayevent(). how can i do this. plz help me someone. Hi folks, Any suggestions on how you might achieve the following without using eval()? I've come up a bit short Code: function addOrSubtract(operator) { var a = 10; var b = 5; var answer = eval(a + operator + b); alert(answer); } addOrSubtract('+') // alerts 15 addOrSubtract('-') // alerts 5 Would help me tidy up some code a lot thanks. Hello, I am trying to access a dynamic asp variable with onclick either in a javascript function where I can use it globally or set another div id with this dynamic variable. Any help is very much appreciated. Thank you! <script> function doSomething(article_id) } return article_id; } </script> <a href="#test" onClick="doSomething("<%=rsHeadline("article_id")%>")">try here...</a> <div id="test"> <%articleid = request.querystring("article_id") %> <% Response.Write articleid %> The article id is articleid</div> Hello all I have a big problem I have my php like this Code: <? $codid=$_GET["cid"]; echo " <script> setTimeout(function() {CSelect();}, 100) ; </script> <div id=\"ReloadThis\"></div>"; ?> And my js funtion Code: function CSelect() { var $http, $self = arguments.callee; if (window.XMLHttpRequest) { $http = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { $http = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { $http = new ActiveXObject('Microsoft.XMLHTTP'); } } if ($http) { $http.onreadystatechange = function() { if (/4|^complete$/.test($http.readyState)) { document.getElementById('ReloadThis').innerHTML = $http.responseText; setTimeout(function(){$self();}, 10); } }; $http.open('GET', 'linii_c/select.php'+'?cod='+' PHP VARIABLE ', true); $http.send(null); } } who i can put my php variable into the funtion? Thanx in advence and sorry for my bad english! Hi All I have this basic auto complete JavaScript that works well, but you need to hard code the web page. What I'm trying to do is send the "Autocomplete" variable data to the page using a perl script the working JavaScript code looks like this: var CustomArray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML'); Now the new code is: var CustomArray=new Array(Autocomplete); And the Perl script is sending back the data to the browser looking like this: var Autocomplete = 'an apple','alligator','elephant','pear','kingbird','kingbolt','kingcraft','kingcup','kingdom','kingfish er','kingpin','SML' I cant seem to get it to work rite full HTML code is below any help is appreciated. HTML: <html> <head> <script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Autocomplete.js"></script> <script language="javascript" type="text/javascript" src="http://www.comicinvasion.com/Code/Java/Autocomplete/Common.js"></script> <script language="JavaScript1.2" type="text/javascript" src="http://www.ComicInvasion.com/cgi-bin/Autocomplete.pl"></script> <script> var CustomArray=new Array(Autocomplete); </script> </head> <body> <input type='text' style='font-family:verdana;width:300px;font-size:12px' id='ACMP' value=''/> <script> var obj = actb(document.getElementById('ACOMP'),CustomArray); </script> </body> </html> hi guyz i do have a problem in passing javascript variable to <input type=hidden value=""> here's my code: <?php while ($row = mysql_fetch_array($result)) { ?> <script type="text/javascript"> function viewcodec(){ var randomValueCodec = randomString(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'); document.getElementById('commentMarkCodeCompCodec-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; document.getElementById('commentMarkCodeComp-'+<?php echo $row['p_id'];?>).innerHTML = randomValueCodec; } </script> <form action="" method="post" name="postsForms"> <div class="commentBox" align="right" id="commentBox-<?php echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>> <input type=text id="commentMarkname-<?php echo $row['p_id'];?>" name="commentmarkname" class="commentMarkname" size="35" maxlength="20"> <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" name="commentmark" cols="60"></textarea> <input type=text id="commentMarkcode-<?php echo $row['p_id'];?>" name="commentmarkcode" class="commentMarkcode" size="35" maxlength="20"> <br clear="all" /> <span id='commentMarkCodeCompCodec-<?php echo $row['p_id'];?>'><b><script type="text/javascript">viewcodec();</script></b></span> <input type="hidden" id="commentMarkCodeComp-<?php echo $row['p_id'];?>" name="commentMarkCodeComp" value=""> <br clear="all" /> <br clear="all" /> <a id="SubmitComment" style="float:right" class="small button comment"> Comment</a> </div> </form> <?php } ?> How to: pass local variable from <head> JS function to <body> textarea I have a JS function in the head that calculates a variable. the function is triggered by the vevent of a button click. when calculation is done, how is it sent back to the page and placed in a textarea or textbox....?? /Beginner issues :/ Hi, I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it. I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page. Thanks for all the help P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side... Here is my code <script language="javascript" type="text/javascript"> function revealModal(divID) { window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop; }; document.getElementById(divID).style.display = "block"; document.getElementById(divID).style.top = document.body.scrollTop; } function hideModal(divID) { document.getElementById(divID).style.display = "none"; } </script> <div id="modalPage3"> <div class="modalBackground"></div> <div class="modalContainer"> <div class="modal53"> <div class="modalTop"><a href="javascript:hideModal('modalPage3')">[X]</a></div> <div class="modalBody"> <?php echo 'value='.$_SERVER['value']; ?> <h3><center>Choose from the options below</center></h3> <center><div id="stylized" class="myform"> <a href="javascript:hideModal('modalPage3');javascript:revealModal('modalPage1')" tabindex="2" title="Remove UPCAT Passer"><img src="images/photo_remove.png" /></a> <a href="javascript:hideModal('modalPage3');javascript:revealModal('modalPage2')" tabindex="4" title="Edit UPCAT Passer"><img src="images/photo_edit.png" /></a> <a href="javascript:hideModal('modalPage3');javascript:revealModal('modalPage4')" tabindex="4" title="Change Status of UPCAT Passer"><img src="images/photo_up.png" /></a> </div></center> </div> </div> </div> </div> <a href=javascript:revealModal('modalPage3');> <img src=images/option.jpg /></a> my problem is this one..how can I pass a value example value=3 to be like href= index.php?value=3..PLEASE HELP!!! I'm using a geolocator service to find the zipcode of a web page visitor using the code below. This will be used to serve up ads to the visitor based on their zip code. The question is, how do I pass the zip code value from the script into an ASP variable, such as a cookie or session object? <script language="JavaScript" src="http://www.iplocationtools.com/iplocationtools.js?key=my_site_key"></script> <script language="JavaScript"> <!-- document.write(ip2location_zip_code()); //--> </script> Is it possible to pass the id onChange like in this example instead of the value This is part of a large complex script, and I need the id as seperate function Code: <select name='color' onChange='this.form.F1.value=this.form.color.id' > <option value='Green' id='c1'>Green <option value='Red' id='c2'>Red <option value='Blue' id='c3'>Blue </select> <input type="text" name="F1" size="15" value="" onChange="this.value=this.form.color.id"> Hi All, have a script which already passes one varible from a php script to my js script but i am having trouble trying to pass another one. here is my php code PHP Code: <?php include("config.php"); $keyword = $_POST['data']; $sql = "select prodName from ".$db_table." where ".$db_column." like '".$keyword."%' limit 0,10"; $result = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($result)) { echo '<ul class="list">'; while($row = mysql_fetch_array($result)) { $prodCat = $row['category']; $str = $row['prodName']; $start = strpos($str,$keyword); $end = similar_text($str,$keyword); $last = substr($str,$end,strlen($str)); $first = substr($str,$start,$end); $link = ""; $final = '<span class="bold">'.$first.'</span>'.$last; echo '<li><a href="'.$link.'">'.$final.'</a></li>'; } echo "</ul>"; } else echo 0; ?> and here is my original js code Code: $(document).ready(function(){$(document).click(function(){$("#ajax_response").fadeOut('slow');});$("#keyword").focus();var offset=$("#keyword").offset();var width=$("#keyword").width()-2;$("#ajax_response").css("left",offset.left);$("#ajax_response").css("width",width);$("#keyword").keyup(function(event){var keyword=$("#keyword").val();if(keyword.length) {if(event.keyCode!=40&&event.keyCode!=38&&event.keyCode!=13) {$("#loading").css("visibility","visible");$.ajax({type:"POST",url:"ajax_server.php",data:"data="+keyword,success:function(msg){if(msg!=0) $("#ajax_response").fadeIn("slow").html(msg);else {$("#ajax_response").fadeIn("slow");$("#ajax_response").html('<div style="text-align:left;">No Matches Found</div>');} $("#loading").css("visibility","hidden");}});} else {switch(event.keyCode) {case 40:{found=0;$("li").each(function(){if($(this).attr("class")=="selected") found=1;});if(found==1) {var sel=$("li[class='selected']");sel.next().addClass("selected");sel.removeClass("selected");} else $("li:first").addClass("selected");} break;case 38:{found=0;$("li").each(function(){if($(this).attr("class")=="selected") found=1;});if(found==1) {var sel=$("li[class='selected']");sel.prev().addClass("selected");sel.removeClass("selected");} else $("li:last").addClass("selected");} break;case 13:$("#ajax_response").fadeOut("slow");$("#keyword").val($("li[class='selected'] a").text());searchValue=document.getElementById('keyword').value;window.location="/dvd/"+searchValue+".php";break;}}} else $("#ajax_response").fadeOut("slow");});$("#ajax_response").mouseover(function(){$(this).find("li a:first-child").mouseover(function(){$(this).addClass("selected");});$(this).find("li a:first-child").mouseout(function(){$(this).removeClass("selected");});$(this).find("li a:first-child").click(function(){$("#keyword").val($(this).text());$("#ajax_response").fadeOut("slow");});});}); and i tryed to pass the $prodCat value by changing the above code and adding the code in red Code: $(document).ready(function(){$(document).click(function(){$("#ajax_response").fadeOut('slow');});$("#keyword").focus();var offset=$("#keyword").offset();var width=$("#keyword").width()-2;$("#ajax_response").css("left",offset.left);$("#ajax_response").css("width",width);$("#keyword").keyup(function(event){var keyword=$("#keyword").val(); var category=$("#prodCat").val(); if(keyword.length) {if(event.keyCode!=40&&event.keyCode!=38&&event.keyCode!=13) {$("#loading").css("visibility","visible");$.ajax({type:"POST",url:"ajax_server.php",data:"data="+keyword,success:function(msg){if(msg!=0) $("#ajax_response").fadeIn("slow").html(msg);else {$("#ajax_response").fadeIn("slow");$("#ajax_response").html('<div style="text-align:left;">No Matches Found</div>');} $("#loading").css("visibility","hidden");}});} else {switch(event.keyCode) {case 40:{found=0;$("li").each(function(){if($(this).attr("class")=="selected") found=1;});if(found==1) {var sel=$("li[class='selected']");sel.next().addClass("selected");sel.removeClass("selected");} else $("li:first").addClass("selected");} break;case 38:{found=0;$("li").each(function(){if($(this).attr("class")=="selected") found=1;});if(found==1) {var sel=$("li[class='selected']");sel.prev().addClass("selected");sel.removeClass("selected");} else $("li:last").addClass("selected");} break;case 13:$("#ajax_response").fadeOut("slow");$("#keyword").val($("li[class='selected'] a").text());searchValue=document.getElementById('keyword').value; searchCategory=document.getElementById('category').value; window.location=" /"+searchCategory+"/"+searchValue+".php ";break;}}} else $("#ajax_response").fadeOut("slow");});$("#ajax_response").mouseover(function(){$(this).find("li a:first-child").mouseover(function(){$(this).addClass("selected");});$(this).find("li a:first-child").mouseout(function(){$(this).removeClass("selected");});$(this).find("li a:first-child").click(function(){$("#keyword").val($(this).text());$("#ajax_response").fadeOut("slow");});});}); but this breaks the js code and it prevents it from running any ideas what ive done wrong? thanks Luke |