JavaScript - Append Variable To Url In Multiple Drop Down Page.
I have a page with multiple drop down menus for selecting a State then City, then Zip. The State and City both work fine but I can't seem to make the Zip function properly.
Page with drop downs: Code: var xmlhttp; function showCity(state) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_cities.php"; url=url+"?q="+state; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } var s=state; function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } var xmlhttp; function showZip(city) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_zips.php"; url=url+"?z="+city; url=url+"&q="+s; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged1; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged1() { if (xmlhttp.readyState==4) { document.getElementById("txtZip").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } <!--********** state drop down *********--> <? $State = mysql_query("SELECT DISTINCT full_state FROM zip_codes ORDER by full_state",$db_link); ?> <select name="state" CLASS="formTextbox" size="1" onChange="showCity(this.value)"> <? while($get = mysql_fetch_array($State)) { ?> <option value="<?=$get['full_state'];?>"><?=$get['full_state'];?></option><? } ?> </select> get_cities.php: Code: <?php $q=$_GET["q"]; include('include/db_con.php'); ?> <? $City = mysql_query("SELECT DISTINCT city FROM zip_codes WHERE full_state = '$q' ORDER BY city",$db_link); ?> <select name="city" CLASS="formTextbox" size="1" onChange="showZip(this.value)"> <? while($get = mysql_fetch_array($City)) { ?> <option value="<?=$get['city'];?>"><?=$get['city'];?></option><? } ?> </select> get_zips.php: Code: <?php $z=$_GET["z"]; $q=$_GET["q"]; include('include/db_con.php'); ?> <? $Zip = mysql_query("SELECT DISTINCT zip FROM zip_codes WHERE city = '$z' AND full_state = '$q' ORDER by zip",$db_link); ?> <select name="zip" CLASS="formTextbox" size="1"> <? while($get = mysql_fetch_array($Zip)) { ?> <option value="<?=$get['zip'];?>"><?=$get['zip'];?></option><? } ?> </select> I have my page set to only show the drop down's when there is a value to select. The Zip drop down shows up at the correct time but is empty. I've tried searching the forum but since I'm still learning js I wasn't able to make use of any on the other multiple drop down examples I came accross. Thanks for any advice you can offer. Similar TutorialsI am looking to scan a page, find all the url's on the page. Once I have them, I want to append the front of the url (hardcoded and never changes) with hardcoded code. Like a Find and Replace. for example: locate the front of all the urls which is - wincfprod032 and replace with wincfprod032.jewels 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... http://www.javascriptkit.com/howto/drag.shtml Has anyone modified this script to drag multiple items? I am creating a quote calculator as a mobile app using the JQuery Mobile plugin in Dreamweaver CS5.5. This supports HTML5 & Javascript. I have included a drop down list in which the user selects a specific Annual Volume. I have 2 different calculations that need to be done based on the users selection. Different calculations meaning that I need 2 different number values assigned to the option. For Example: Calculation #1 (I'm calculating what the Run Quantity is based on what the user selects as the Annual Volume. If user selects an Annual Volume of 150,000 then the calculated result for Run Quantity needs to be 3500) HTML for this scenario: Code: <li data-role="fieldcontain"> <p><span class="ui-listview-inset">Annual Volume:</label> <select name="annualvolume" id="annualvolume"> onChange="Calculate();"> <option value="1000">10,000</option> <option value="2000">30,000</option> <option value="3500">150,000</option> <option value="6000">300,000</option> <option value="10000">500,000</option> <option value="20000">1,000,000</option> </select> </p> </li> Calculation #2 (within the same form as the above calculation, I also need to calculate what the Annual Sales will be. The math to calculate the Annual Sales is to multiply the Final Piece Price (which is another calculation within this form) with Annual Volume. However with this Calculation # 2 I need the value to be 150,000 when user selects 150,000 and NOT 3500 as it was before. I've tried tweaking the HTML in following manner to assign 2 values within the same drop down, but it didn't work correctly. Code: <option value="3500" amount="150000">150,000</option> My javascript is as follows (please note that I deleted all the result fields except for the 3 that reference my described calculations above. My actual calculator has over 20 results all based on the user's inputs. This is why there are so many variables listed in my javascript - they are for the other results) Code: <SCRIPT LANGUAGE="JavaScript"> function CalculateSum(Atext, Btext, materialtype, presstype, Etext, Ftext, annualvolume, annualvolume2,Htext, Itext, form) { //INPUTS var A = parseFloat (Atext); var B = parseFloat (Btext); var C = document.getElementById('materialtype').value; var D = document.getElementById('presstype').value; var E = parseFloat (Etext); var F = parseFloat (Ftext); var G = document.getElementById('annualvolume').value; var GA = document.getElementById('annualvolume').amount; var H = parseFloat (Htext); var I = parseFloat (Itext); //RESULTS form.RunQuantity.value = G form.FinalPiecePrice.value = (((C*A) + F) + ((D/G) + E) + (((C*A) + F) + ((D/G) + E )) * (H *.01) + (((C*A) + F) + ((D/G) + E ) + (((C*A) + F) + ((D/G) + E )) * (H *.01)) * (I *.01)) form.AnnualSales.value = (form.FinalPiecePrice.value * GA) } </script> Currently I am simply having the user enter the annual volume twice so I can do the 2 calculations, but this is really clunky and not ideal. I'm fairly new to Javascript but have learned a lot from reading other posts by people like you. This is the first thing I haven't been able to figure out on my own and any help would be greatly appreciated. Hi, This code works as it should, but I want to enhance it so that it does a search by category within the Regions/Provinces selected. But I'm not an expert with Javascript, actually the complete reverse. This if for a classified ads website, so the categories are like cars, homes, etc Code: <html> <head> <title></title> <meta content=""> <style></style> <script language="JavaScript"> function loadPage(list) { location.href=list.options[list.selectedIndex].value } </script> </head> <body> <table align="center"> <tr> <td> <form> <div align="center"> Search by <select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top" onmouseclick="this.focus()"> <option value select="selected">Regions</option> <option value="http://www.apple.com">Region 1</option> <option value="http://www.apple.com">Region 2</option> <option value="http://www.apple.com">Region 3</option> </select> </form> </td> <td> <form> or <select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top" onmouseclick="this.focus()"> <option value select="selected">Provinces</option> <option value="http://www.apple.com">Province 1</option> <option value="http://www.apple.com">Province 2</option> <option value="http://www.apple.com">Province 3</option> </select> </div></form> </td></tr></table> </body> </html> Any help would be appreciated. Or any improvements would also be appreciated. Also, any help in converting the table to CSS would be appreciated. Hey all, I was just wondering if you could help me out with the following, I've done a bit of google searching but haven't come up with anything. Basically, there will be 3 drop down boxes (Option a, Option b, Option c) In each drop down box there will be 3 options (One, Two, Three) Whats a script I can use that will write on page :Yellow If they select: Option a - One Option b - One Option c - Three Of the script will write blue if they selection Option a - Two Option b - One Option c - One Hi there, i've run into a bit of a problem, i've managed to get javascript to change an image when choosing an option from a dropdown menu, but when i try to get it to change multiple images it only ever changes one image... Code: <script type="text/javascript"> function changeWalls(what, whatimg) { if(what != "none") { document.images[whatimg].src = what; } } </script> <select name="Walls" onchange="changeWalls(this.value,'walls')"> <option value="images/white.gif" selected="selected">Please Select a Colour</option> <option value="images/WALLCC.png">Classic Cream</option> <option value="images/WALLSG.png">Shale Grey</option> <option value="images/WALLDO.png">Deep Ocean</option> <option value="images/WALLSM.png">Surfmist</option> </select> then the images i want are multiples so i want to change 2 of these Code: <img src="images/front_0002_front-wall-colour.png" alt="" name="walls" border="0" id="walls2" /> I am using the following code to show / hide form elements within a div based upon the drop down choice. Does anyone know how this code can be amended to use multiple drop downs within one form? Code: <html> <head> <title>Show and Hide</title> <script> //********************************************* // Function that Shows an HTML element //********************************************* function showDiv(divID) { var div = document.getElementById(divID); div.style.display = ""; //display div } //********************************************* // Function that Hides an HTML element //********************************************* function hideDiv(divID) { var div = document.getElementById(divID); div.style.display = "none"; // hide } //***************************************************************************** // Function that Hides all the Div elements in the select menu Value //***************************************************************************** function hideAllDivs() { //Loop through the seclect menu values and hide all var selectMenu = document.getElementById("selectMenu"); for (var i=0; i<=selectMenu.options.length -1; i++) { hideDiv(selectMenu.options[i].value); } } //********************************************* // Main function that calls others to toggle divs //********************************************* function toggle(showID) { hideAllDivs(); // Hide all showDiv(showID); // Show the one we asked for } </script> </head> <body onload="hideAllDivs();"> <select id="selectMenu" onchange="toggle(this.options[this.options.selectedIndex].value)"> <option value="formNumber1"> Show Form 1 </option> <option value="formNumber2"> Show Form 2 </option> <option value="formNumber3"> Show Form 3 </option> <option value="formNumber4"> Show Form 4 </option> </select> <div id="formNumber1"> I am Form Number one. Any content within this div will be showed</div> <div id="formNumber2"> I am Form Number two. Any content within this div will be showed</div> <div id="formNumber3"> I am Form Number three. Any content within this div will be showed</div> <div id="formNumber4"> I am Form Number four. Any content within this div will be showed</div> </body> </html> Thanks in advance! Hello, i want to integrate dropdown combobox menu on my website for pricing, i want the same like it is on the following link: Web Hosting - Shared cPanel Web Hosting and on this website there is no choose currency option, but i have set on my website on the corner of the top side. how can i do this? Regards, Alex C Hi all, I've been trying to teach myself Javascript to figure out this problem, but I'm apparently not learning what I need to. The objective is this: I want to have a div appear below my mouse when mousing over different parts of my website. I know how to swap out the background images, I know how to change the div's sizes... It's just that I'm using one div, and in order to get this right, I need it to be positioned in different places under the mouse each time the image changes. I've got a cross-browser mouse-follow worked out, I just don't know how to edit the "divvx" and "divvy" variables when I mouse over the "boxtest" div. Here is the code I'm working on, maybe I'm just missing something obvious? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <script type="text/javascript"> var divvx=22, divvy=22; function doMouseMove(e){ var posx=0;var posy=0; var e=(!e)?window.event:e;//IE:Moz if (e.pageX){//Moz posx=e.pageX+window.pageXOffset; posy=e.pageY+window.pageYOffset; } else if(e.clientX){//IE if(document.documentElement){//IE 6+ strict mode posx=e.clientX+document.documentElement.scrollLeft; posy=e.clientY+document.documentElement.scrollTop; } else if(document.body){//Other IE posx=e.clientX+document.body.scrollLeft; posy=e.clientY+document.body.scrollTop; } } else{return false}//old browsers var mydiv=document.getElementById('curicon'); mydiv.style.left=(posx-divvx)+'px'; mydiv.style.top=(posy-22)+'px'; } document.onmousemove=doMouseMove function MM_callJS(jsStr) { //v2.0 return eval(jsStr) } </script> <style type="text/css"> <!-- #curicon { background-image: url(resources/cursors/Inactive_Halo.png); height: 44px; width: 44px; position: absolute; top: -80px; left: -80px; } #boxtest { position: absolute; height: 100px; width: 400px; background-color: #0F0; left: 149px; top: 213px; } --> </style> </head> <body> <div id="curicon" name="curicon" style="position:absolute; left:-250px; z-index:2"></div> <div id="boxtest" onMouseOver="MM_callJS('divvx=68')"></div> </body> </html> Thanks, everyone. This has been driving me nuts for an entire week. Hi to all, Sorry to ak this question it may be easy but i didn't got the solution on net please provide the proper answer. My question is : I am defining hyperlink in struts as <a href= Javascript:formSubmit(<bean:write name="AA" property="aa">','<bean:write name="BB" property="bb">) defining function as function formSubmit(Aa,Bb) { document.forms[0].action="/accesingpage.do?method=create&AA=+Aa" ----> in above statement how to pass the second parameter(i.e Bb)....I tried different ways but giving syntax error. please post the ans as soon as possible I got no idea how to create a filter based on multiple drop menus to filter & sort data from php mysql query. Can anyone help me to write javascipt for this problem? My php mysql query as below:- mysql_select_db($database_winwin, $winwin); $query_rsMobile = "SELECT product_detail.product_Id, product_detail.product, product_detail.product_category, product_detail.product_brand, product_detail.product_name, product_detail.product_price, product_detail.thumbnail_url, product_detail.product_url, product_detail.product_status, product_detail.commission, product_detail.product_added_date FROM product_detail WHERE product_detail.product='Mobile Devices' AND product_detail.product_status='For sales'"; $rsMobile = mysql_query($query_rsMobile, $winwin) or die(mysql_error()); $row_rsMobile = mysql_fetch_assoc($rsMobile); $totalRows_rsMobile = mysql_num_rows($rsMobile); Whereby:- Product Brand: product_brand Product price: product_price Commission: commission Product name: product_name Product Thumbnail: thumbnail_url Product URL: product_url HTML for filters & sorter:- <div id="filters"> <form action="" method="post" name="form_filters" id="form_filters"> <table width="750" border="0"> <tr> <td>Brand:</td> <td><select name="productBrand" id="productBrand"> <option value="All Brands">All Brands</option> <option value="Sony Ericsson">Sony Ericsson</option> <option value="Samsung">Samsung</option> <option value="Nokia">Nokia</option> </select></td> <td>Price:</td> <td><select name="priceRange" id="priceRange"> <option value="All Price">All Price</option> <option value="Below RM1000">Below RM1000</option> <option value="RM1000-RM1999">RM1000-RM1999</option> <option value="RM2000 & Above">RM2000 & Above</option> </select></td> <td>Sort by:</td> <td><select name="productSort" id="productSort"> <option value="Sort By Name">Name</option> <option value="Sort By Price">Price</option> </select></td> <td><input name="Apply Filters" type="submit" value="Apply Filters"/></td> <td><input name="Reset Filters" type="Reset" value="Reset Filters"/></td> </tr> </table> </form> </div> Once user click on "Apply Filters" javascript has to sort list the product items. HTML for Pager (Value for total items, display some page numbers with hyperlink (1,2,3....10,11,12), hyperlink to previous page, hyperlink to next page) :- <div id="pager"> No. of items per page: <select name="NumOfItem" id="NumOfItem"> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> </select> Total Item: Pages ... Next... Previous </div> Javascript has to manage pager column. HTML for Product display:- <div id="product"> <div id="Thumbnail"> Here Javascript has to display Thumbnail image based on filters & sorter drop menus inputs. When click on this image page must redirect to "Product URL". </div> <div id="Price"> Here Javascript has to display "Price" based on filters & sorter drop menus inputs. When click on this "Price" page must redirect to "Product URL". </div> <div id="Commission"> Here Javascript has to display "Commission" image based on filters & sorter drop menus inputs. When click on this "Commission" page must redirect to "Product URL". </div> </div> Javascript has to repeat regions (<div id="product"></div>)based on "NumOfItem" drop menu (number of items display per page) and also update the pager column I have the following code in a website which is the W3C method of loading XML/XSL via Javascript. The code works perfectly except as you can see from the last line of code it appends the fixed div. This is not suitable as I need the site to overwrite the contents of the fixed div (not append). How could I rewrite that last line of code so that the data within the fixed div is rewritten with the contents of resultDocument. innerHTML doesn't work since the content of resultDocument is an XML file. Code: xml=loadXMLDoc("dating_database.xml"); { xsltProcessor=new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml,document); document.getElementById("fixed").appendChild(resultDocument); } Hi Chaps, I have thumbnail gallery which, when clicked opens up a large version in a div. PHP Code: <p><img id="largeImg" src="images/img1-lg.jpg" alt="Large image" /></p> <p class="thumbs"> <a href="images/img2-lg.jpg" title="Image 2"><img src="images/img2-thumb.jpg" /></a> <a href="images/img3-lg.jpg" title="Image 3"><img src="images/img3-thumb.jpg" /></a> </p> The jQuery Code: Code: $(document).ready(function(){ $(".thumbs a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); $("#largeImg").attr({ src: largePath, alt: largeAlt }); }); }); With a bit of CSS, this is working fine. What I'm trying to do is to: 1. Add attribute to: PHP Code: <p class="thumbs"> <a href="images/img2-lg.jpg" zoom="images/img2-zoom.jpg" title="Image 2"><img src="images/img2-thumb.jpg" /></a> <a href="images/img3-lg.jpg" zoom="images/img3-zoom.jpg" title="Image 3"><img src="images/img3-thumb.jpg" /></a> </p> 2. Add <a id="img_zoom"> to: PHP Code: <p><a id="img_zoom"><img id="largeImg" src="images/img1-lg.jpg" alt="Large image" /></a></p> 3. Add to the jQuery code, to append the "<a>" link, something like: Code: $(document).ready(function(){ $("img_zoom").append('" href="') $(".thumbs a").click(function(){ var largePath = $(this).attr("href"); var largeAlt = $(this).attr("title"); var zoomPath = $(this).attr("zoom"); $("#largeImg").attr({ src: largePath, alt: largeAlt }); $("img_zoom").html(zoomPath+" " "); return false; }); }); So when the thumbnail image is clicked, the resulting jQuery output would be something like this: Quote: <a id="img_zoom" href="images/img3-zoom.jpg"> Is this do-able? I've played around with it for ages and can't get it to work. Any hlep would be awesome! edit: I further identified the problem. Hi, I'm new to JavaScript and I'm having problem with appending a div node returned from a function. Here's where it crashed: Code: var div=document.getElementById("dashboard_secondary_cat_list"); var s=get_secondary_cat_node(attributes); alert("b4 appendin:"+s); div.appendChild(s); alert("done appendin"); alert("done appendin"); never gets called because the previous line crashes. alert("b4 appendin:"+s); shows: b4 appendin:[object HTMLDivElement] I am trying to make a lightbox type plugin and I am running into a problem. I hope it is something simple that I am overlooking. Here is my code: jQuery.fn.overlay = function() { $(this).click(function() { $('body').append('<div id="over"></div>'); $('#over').fadeIn(); }); }; It (almost) does what it should. It draws the #over div to the screen just fine. The problem is when I try to access it. I try something like this and get no response: $(function() { $('#over').click(function() { alert('moo'); }); }); Its like the element is not getting the ID assigned to it. Does anyone have any ideas? Thanks in advance. I want to append a string "&sid=xyz" to the current page URL if the referring URL comes from site www.xyz.com. I have the following code - var query = location.search.substring(1); if (document.referrer.indexOf(/xyz/) > 0) { query = query + "&sid=xyz"; } However, the string is not being appended. Can anyone see where the problem lies? Hi I am new to javascript programming. Is it possible to append an event handler to a tag dynamically. <input type="button" id="cmdNext" value="Next Page"> i want to be able to programatically loop through the buttons on a page and then add the onClick event. So my finally result will be the following: <input type="button" id="cmdNext" value="Next Page" onClick="CheckValues()"> Since i am new (if possible) can someone provide detail code example so i can break it down and study it before i implement. I have following JS snippet var t = document.createElement ('div'); t.id = "testDiv"; t.innerHTML = "test content"; window.top.document.getElementById ('anotherDiv').appendchild (t); 'anotherDiv' exists in the document; The statement above is not working in IE I'm seeing JS error. but it works in Firefox (i.e t element is appended to anotherDiv). Can any one please let me know how i can resolve this. |