Javascript Database Dependent Dropdowns?
Sep 13, 2006
How would I make my page I have connect to a database using javascript dependent dropdowns? I have all the things I need to get the database working where it displays all the info in the database but I only want it to display based on what they select not all of it.
<?php require_once('Connections/conn_dj.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_industry = "SELECT * FROM tbl_industry ORDER BY industry_name ASC";
$rs_industry = mysql_query($query_rs_industry, $conn_dj) or die(mysql_error());
$row_rs_industry = mysql_fetch_assoc($rs_industry);
$totalRows_rs_industry = mysql_num_rows($rs_industry);
mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_productcategory = "SELECT * FROM tbl_productcat ORDER BY tbl_productcat.productCat_name";
$rs_productcategory = mysql_query($query_rs_productcategory, $conn_dj) or die(mysql_error());
$row_rs_productcategory = mysql_fetch_assoc($rs_productcategory);
$totalRows_rs_productcategory = mysql_num_rows($rs_productcategory);
mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_product = "SELECT * FROM tbl_products ORDER BY tbl_products.products_name";
$rs_product = mysql_query($query_rs_product, $conn_dj) or die(mysql_error());
$row_rs_product = mysql_fetch_assoc($rs_product);
$totalRows_rs_product = mysql_num_rows($rs_product);
mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_outsidena = "SELECT * FROM intl_countries ORDER BY intl_countries.name";
$rs_outsidena = mysql_query($query_rs_outsidena, $conn_dj) or die(mysql_error());
$row_rs_outsidena = mysql_fetch_assoc($rs_outsidena);
$totalRows_rs_outsidena = mysql_num_rows($rs_outsidena);
mysql_select_db($database_conn_dj, $conn_dj);
$query_rs_state = "SELECT * FROM tbl_states ORDER BY tbl_states.`state`";
$rs_state = mysql_query($query_rs_state, $conn_dj) or die(mysql_error());
$row_rs_state = mysql_fetch_assoc($rs_state);
$totalRows_rs_state = mysql_num_rows($rs_state);
?>
<!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>
<title>DICKEY-john Corporation | Distributors</title>
<link href="_lib/sub.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="Distributor, Sales, Purchase, U.S., International" />
<meta name="description" content="Enter your zip or postal code to find the DICKEY-john distributor nearest you." />
</head>
<body>
<div id="black"> </div>
<div id="siteContainer">
<?php include("_inc/topNav.inc"); ?>
<div id="headerContainer">Distributors</div>
<div class="divContainer"><div class="horizDiv"></div><img src="/_img/divEnd.png" alt="div" height="16" width="4" align="right" /></div>
<div id="contentContainer">
<div id="fullContainer">
<div id="stretchCrumbs">
<a href="/index.php">Home</a>
» <a class="high" href="/distributors/">Distributors</a>
</div>
<h1>Distributors</h1>
<p>Search for DICKEY-john distributers by specifying any combonation of the<br />
following classifications: industry, product category, product, and state.</p>
<br />
<br />
<h2>North America</h2>
<table class="setTbl listTbl" width="90%" cellpadding="0" cellspacing="0" border="0">
<tr><td>Industry:</td><td>
<select name="industry" id="center">
<option value="">Select an Industry...</option>
<?php do { ?>
<option value="<?php echo $row_rs_industry['industry_name']; ?>"><?php echo $row_rs_industry['industry_name']; ?></option>
<?php } while ($row_rs_industry = mysql_fetch_assoc($rs_industry)); ?>
</select></td></tr>
<tr><td width="125">Product Category: </td> <td>
<select name="prodcat" id="center">
<option value="">Select a product category...</option>
<?php do { ?>
<option value="<?php echo $row_rs_productcategory['productCat_name']; ?>"><?php echo $row_rs_productcategory['productCat_name']; ?></option>
<?php } while ($row_rs_productcategory = mysql_fetch_assoc($rs_productcategory)); ?>
</select></td></tr>
<tr>
<td>Product:</td> <td>
<select name="prod" id="center">
<option value="">Select a product...</option>
<?php do { ?>
<option value="<?php echo $row_rs_product['products_name']; ?>"><?php echo $row_rs_product['products_name']; ?></option>
<?php } while ($row_rs_product = mysql_fetch_assoc($rs_product)); ?>
</select> </td></tr>
<td>State:</td>
<td> <select name="state" id="center">
<option value="">Select a state...</option>
<?php do { ?>
<option value="<?php echo $row_rs_state['state']; ?>"><?php echo $row_rs_state['state']; ?></option>
<?php } while ($row_rs_state = mysql_fetch_assoc($rs_state)); ?>
</select></td>
</tr>
<tr><td> </td><td><input class="PythonButton" type="submit" value="Find" name="{Button_Name}"></td></tr>
</table>
</form>
<br />
<h2>Outside North America </h2>
<table class="setTbl listTbl" width="90%" cellpadding="0" cellspacing="0" border="0">
<tr><td> <select name="outna" id="center" onchange="javascript:document.centerform.submit()">
<option value="">Select a country...</option>
<?php do { ?>
<option value="<?php echo $row_rs_ousidena['name']; ?>"><?php echo $row_rs_outsidena['name']; ?></option>
<?php } while ($row_rs_outsidena = mysql_fetch_assoc($rs_outsidena)); ?>
</select></td>
</tr></td></tr>
</table>
</form>
</div>
</div>
<?php include("_inc/footer.inc"); ?>
</body>
</html>
<?php
mysql_free_result($rs_industry);
mysql_free_result($rs_productcategory);
mysql_free_result($rs_product);
mysql_free_result($rs_outsidena);
mysql_free_result($rs_state);
?>
View 3 Replies
ADVERTISEMENT
Oct 12, 2010
I have a calculate.js javascript file where all the function that execute the calculation is consist in this file. Now, I want to retrieve a data from the database for javascript calculation and be done in this calculate.js file. I have search a lot of methods to do this but most said cannot do this from a client-side.
View 9 Replies
View Related
Mar 25, 2007
Does anyone know if this is possible to have a online database? Or can I use access to make a database and then post it online and have it work on the internet?
View 2 Replies
View Related
Apr 27, 2006
I want to make a database which I can put on my USB flash drive, with a html interface, and maybe an xml database. Will I be able to do that?
View 1 Replies
View Related
Dec 27, 2004
i'm having the user input their state (from a drop down list) and type in a zipcode (there are 1,143 zip codes in the database to match to)..
what i want to happen is once the user selects the state they live in, and type in a zip code, i need the page to query the database if the user selected Ohio, and match the counties in the database with the zip code they entered, and then create a drop down list of the counties for them to select the one they live in Code:
View 1 Replies
View Related
Nov 20, 2006
im trying to get values from a database and assign them to icons which display on my page. The icons that are generated on the page are generated in javascript- and they do work. Howver i want icons to hold the names that are in the database/table.
how would i do this? would this be using a query result in asp to get the values from the database?? how would i do this? please provide code or guide.
then, how would i assign the database value with the icons???? ive heard javascript arrays??? how would i assign the values??
View 1 Replies
View Related
Nov 8, 2007
we had someone write this script for us a few years ago and we thought it was working fine until this week. It uses javascript to generate a dependant drop down menu eg. Depending on what the user chooses in the first drop down menu, (in this case a manual/book title) the second drop down displays the chapter/category headings that are available within that manual and then the users uploads a file that appears under that heading.
If our user adds a chapter/category heading with an apostrophe in it the script quits and the second drop down does not display the corresponding chapter headings. We are storing the info in a mysql database and use php and javascript to extract the data/build the drop down menus. Code:
View 3 Replies
View Related
Mar 16, 2004
Not sure if this is the correct forum as it covers data retrieved from mysql in a .js file...
I need to grab the last 5 rows from my database (2 fields per row) and list all 5 in a table but from within a .js file that I can externally link to.
I can manage the php / mysql and the output to a .php page but how can this be contained within a .js file?
I believe it is possible but after 2 days of searching on google I'm appealing for assistance.
I realise this could be done with a php include or iframe but that isn't an option and the only way available to import this data is via an external javascript script.
View 3 Replies
View Related
May 9, 2007
I have this PHP page that has the following functions...Insert Form into Table in MySQL DatabaseDelete Entry from Table in MySQL DatabaseA Link to a separate page where I Edit entries I have coded a PHP function for Delete. Looks like this:
// delete if provided if (isset($_GET['id'])) { // query to delete $query = "delete from student where STUDENT_ID =".$_GET['id']; //execute query if ($db->query($query)) {
Somewhere else I query the results and print them into a table. I added a column to this table with a Delete link for each row. Clicking on delete will execute the PHP function to delete.
The link looks like this: PHP Code:
echo "<td><a href=".$_SERVER['PHP_SELF']."?id=".$row[0]."></a></td>";
Likewise the first names also have links when clicked bring the user to another page with a form to edit form data.
The link looks like this: PHP Code:
echo "<td><a href='editstudent.php?id=".$row[0]."'>".$row[1]."</a></td>";
From here however I need to change those links to Buttons. One for Delete and another for Edit and use JavaScript functions to make them work as they originally did. So this is what I've done...
<td><form name='myform1'><input type='button' name='edit' value='Edit'
<td><form name='myform2'><input type='button' name='delete' value='Delete'
Next I need to write functions...this is where I am lost. Usually I'd know what to do when referencing elements in forms, i'd do something like document.formname.inputname, but my problem is those links or should I call them actions are replaced by those new buttons.
Should I put them into a form, or make them hidden, and then name the element? Or should my function look something like this...all I really want to do is to call the function, and have the function just do the action of loading the link (don't know if that sounds clear). I've tried to do this but it does not work.
<script>
function Delete()
{
document.myform2.action="href='$_SERVER['PHP_SELF']."?id=".$row[0]'";
document.myform2.submit();
}
</script>
Can anyone tell me what i am doing wrong, and could you please point me in the right direction?
View 6 Replies
View Related
Jul 23, 2005
IE 6.0 (not interested in other browsers at the moment)
I have looked everywhere I can find to look and googled until I am
cross-eyed and am hoping somebody knows what I'm doing wrong.
I have an HTML application (.hta) working fine, except one thing. I'm
trying to write to a local database from a .htm window (opened from
the main .hta window) and it doesn't work with any of the combinations
I've tried (and I admit to having tried a lot).
Here is one method I've tried:
strSQL = "Update myTable SET myField = 'myValue' WHERE myID = 12;"
var db = new ActiveXObject("ADODB.Connection");
db.Provider = "Microsoft.Jet.OLEDB.4.0";0
db.ConnectionString = "Data Source='c:myDirectorymyDatabase.mdb'";
db.Open;
db.execute(strSQL);
I can easily access the information in the myDatabase.mdb and display
it on the screen.
I can ask for updated information to be input on the screen.
But stuffing that updated information back into the database is the
problem.
Since I'm stuck in an .htm window, I don't have VBScript available, do
I? If VBScript isn't available and it isn't physically possible with
Javascript, then I'll have to revert to .hta windows, where I know I
have VBScript available. But I'd rather do it all in Javascript
within the .htm so as to avoid the security message that pops up when
the .hta opens a new .hta. For various reasons I don't think it is
possible for me to do this whole project within a single .hta.
View 9 Replies
View Related
Feb 23, 2006
I am making a webpage that can query a database table of employees
and return them in a html table. Currently I have submit buttons beside
each employee to open the page to edit their details. I have been using
php/HTML to do this, but wondered if it is safe to use javascript to
just click on the name of the employee to jump to the edit page. I've
been looking on the web for sometime about how to do this without any
luck. Any thoughts?
View 1 Replies
View Related
Jan 24, 2011
I have 41 <select> fields in a form. When a user makes any selection or change to any dropdown I want to do ajax and send the values of 41 dropdown's to a php page which will compute the values and return a single value which should be displayed in a div.
View 3 Replies
View Related
Mar 18, 2010
I have been using PHP for a little while but just getting into JavaScript and really need to dynamically update dropdown boxes read from a mySQL database. There are three dropdown boxes, the first reads in fine. The second dropdown box then gets populated using the selection from the first as the condition in mySQL and the same again for the third.The page refreshes itself after the selection from the first box using JavaScript and populates the second using the PHP _GET method (this works fine). The issue is when I need to do this again for the second time because my JS is only set up to do it once and I don't no how to amend it. Also it will have to do it a third time because I need that info to complete the form and update the DB.
<SCRIPT language=JavaScript>
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='bookf.php?cat='+val ;
}
</script>
echo "<form method=post name=f1 action=''>";
////////// Starting of first drop downlist /////////
echo "<select name='cat' onchange="reload(this.form)"><option value=''>Select a Film</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['FilmID']==@$cat){echo "<option selected value='$noticia2[FilmID]'>$noticia2[FilmTitle]</option>"."<BR>";}
else{echo "<option value='$noticia2[FilmID]'>$noticia2[FilmTitle]</option>";}
}
echo "</select><br />";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo "<select name='subcat' onchange="reload(this.form)"><option value=''>Select a Date</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia2['FilmID']==@$cat){echo "<option selected value='$noticia2[FilmID]'>$noticia2[Date]</option>"."<BR>";}
else{echo "<option value='$noticia[FilmID]'>$noticia[Date]</option>";}
}
echo "</select><br />";
////////////////// This will end the second drop down list ///////////
////////// Starting of third drop downlist /////////
echo "<select name='subcat2' onchange="reload(this.form)"><option value=''>Select a Time</option>";
while($noticia = mysql_fetch_array($quer3)) {
if($noticia2['FilmID']==@$cat){echo "<option selected value='$noticia2[FilmID]'>$noticia2[Time]</option>"."<BR>";}
else{echo "<option value='$noticia[FilmID]'>$noticia[Time]</option>";}
}
echo "</select><br />";
////////////////// This will end the third drop down list ///////////
View 1 Replies
View Related
Jul 20, 2005
I have a form with two single-choice dropdowns. Upon doing an onChange event on either one of them, I want to check to see if the other dropdown has also been selected. How would I do that, considering that this.parent causes an error "null or not an object"?
View 2 Replies
View Related
Jan 20, 2006
Does anyone know how to event capture on an autocomplete dropdown - this would not be the underlying html element but only on the autocomplete dropdown itself.
I've never come across trying to capture autocompletes before (in fact, ideally i'm trying to ignore keypresses on the autocomplete and only capture those for the underlying input).
View 5 Replies
View Related
Apr 7, 2009
I'm trying to get a pair of drop down menus to appear on the screen, one containing months, and one containing years. I know the one containing years works, since it hasn't been changed at all since it was working, but the month box used to be a textbox. I tried to convert it over to drop down box using the same code as the year box, but it hasn't seemed to work.
<script language="Javascript">
var m1 = January;
var m2 = February;
var m3 = March;
var m4 = April;
var m5 = May;
var m6 = June;
var m7 = July;
var m8 = August;
var m9 = September;
var m10 = October;
var m11 = November;
var m12 = December; .....
document.write('<select name="selYear">');
for (var x=0; x <= 10; x++ ) {
if(x != 5){
document.write('<option value="' + x + '">' + yearArray[x] + '</option>');
}else{
document.write('<option value="' + x + '" selected>' + yearArray[x] + '</option>');
}} document.write('</select>');
</SCRIPT>
View 9 Replies
View Related
Nov 24, 2005
I am in a problems here trying to generate link by two dropdown boxes. So, I wanted it to be like when user selects some option from dropdown one the href attribute changes, index.php?staticvar=something&dynvar1=something, that is something I have already managed to do:
function change_href(id)
{
if (id != '')
{
var dynvar1 = document.getElementById("s"+id).value;
document.getElementById(id).href = "index.php?staticvar="+id+"&dynvar1="+dynvar1;
return;
}
else
{
return false;
}
}
This works perfectly for me, but now I need to modify the href with another variable, so it would be needed to be like:
index.php?staticvar=something&dynvar1=something&dynvar2=something2
The problem is that I don't know how to make it the way that user can change their selections, for example if user first selects (from dropdown) dynvar1 to be "test" and dynvar2 to be "test3", but then changes hes mind and decides to re-select dynvar2 to be "test4". It would be needed to be like only the dynvar2 part of the href changes with proper value (not changing the dynvar1 or staticvar).
I managed to make it changeable but it was like this:
index.php?staticvar=something&dynvar1=something&dynvar2=123&dynvar2=123
So, it didn't update the dynvar2 part, but instead just added another dynvar2 variable.
View 3 Replies
View Related
Sep 22, 2010
I am looking for the ability to add dropdowns (B, C, D etc) dynamically when one of the option in dropdown (a) is chosen.
View 1 Replies
View Related
Feb 2, 2009
I have 2 different dropdowns lists. One for the month and another for the days (shows the date)
by default when the page is loaded, I am showing January in the first dropdown and 1 in the second dropdown (date).
But if a user selects February from the month dropdown list, I just dont want to show 29th, 30th, 31st etc. Same applicable for say april, june, sept etc where I dont want to show 31st so the user will not be able to select wrong date for a month. How can I do this?
View 1 Replies
View Related
Jul 26, 2010
The datepicker is connected to three fields (drop downs for..) [Month]/[Day]/[Year]-[Datepicker(Calendar)] now I just wanted to get the dropdowns' values and pass it on a textbox (namely: selectedDate - you can see below) having a format of [mm/dd/yyy]
Code from [url]
Update three select controls to match a datepicker selection
The Dropdowns:
View 1 Replies
View Related
Aug 22, 2011
i found this sample code
Code:
<script>
function setOptions(chosen) {
var selbox = document.myform.opttwo;
selbox.options.length = 0;
if (chosen == " ") {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first'
[Code]...
View 6 Replies
View Related
Aug 11, 2010
I am using the following code to show / hide form elements within a div based upon the drop down choice. How this code can be amended to use multiple drop downs within one form?
HTML 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
} .....
View 6 Replies
View Related
Apr 23, 2010
I'm looking for a jQuery AJAX plugin that allows me to do the following. I have three dropdowns ( Make, Model, Year), the values of the second and third dropdowns need to dynamically changed based on the selection of the previous dropdown.
Example:
Dropdown 1
Dropdown 2 ( would change depending on selection in dropdown 1 )
Dropdown 3 ( would change depending on selection in dropdown 2 )
Is there an existing plugin that works?
View 1 Replies
View Related
Jan 16, 2011
I've got a form which I want to validate using jQuery to ensure that the same value for a dropdown has not been entered more than once. The form consists of the following:
Code HTML4Strict:
<li class="clonedInput" id="input1">
Name:
<select id="player[1][userid]" name="player[1][userid]"></select>
<select class="hours" id="player[1][hours]" name="player[1][hours]"></select>
<select class="mins" id="player[1][mins]" name="player[1][mins]"></select>
[Code]...
View 2 Replies
View Related
Oct 1, 2010
refer to following link and you will see first item/option of the first dropdown is being displayed as selected value of other dropdowns. [URL]
View 1 Replies
View Related
Jan 11, 2011
Can i use single jquery and html to do some database manipulation i.e. database transaction.
View 1 Replies
View Related