JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 7th, 2001, 11:34 AM
romerom romerom is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Waterbury, CT
Posts: 1 romerom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to romerom Send a message via AIM to romerom Send a message via Yahoo to romerom
PHP/MySQL/JavaScript/HTML Forms Question

I need help!!

I am trying to figure out a good way to make a usable HTML form that gets its fields from a Database and "onChange" updates the remainder of selected fields.

I have some fields in a MySQL database table: "account, hostname, apptype, appname, version". I want a pull down menu for each one of these fields. When one of these pulldown menu's gets modified (onChange) i want the rest of the pulldown menu's to be updated based on what was changed in the changed pulldown menu. i.e. If i select the hostname "TESTHOST" i only want to see apptype's, appname's and version's that fall under that host. The only way I can think of how to do something like that would be JavaScript but I don't know much about it.

Anybody have any ideas?
If you need me to be more verbose (i.e. samples of data/table layout, samples of scripts) let me know.

Reply With Quote
  #2  
Old August 7th, 2001, 11:49 AM
SilkySmooth's Avatar
SilkySmooth SilkySmooth is offline
Newbie :P
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2001
Location: In the PHP Engine :-)
Posts: 2,880 SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level)SilkySmooth User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 40 m 10 sec
Reputation Power: 20
Mike,

You can do it with a combination of both, here is an example of something I created when I had three feedback forms each for a different feedback type.

<SCRIPT LANGUAGE="JavaScript">
<!--

/* Handles the auto submit element of form */

function displaypage() {
document.forms[0].submit();
}

-->
</SCRIPT>


<SELECT NAME="loadpage" onChange="displaypage()">
<OPTION VALUE="request_for_quote">Request for Quote</OPTION>
<OPTION VALUE="ask_a_question">Ask A Question</OPTION>
<OPTION VALUE="<?echo"$loadpage";?>" SELECTED="SELECTED">--> <?printf("%s", $Format=ucwords($Format1=str_replace("_"," ",$loadpage)));?></OPTION></SELECT>

PHP Code:
if ($loadpage==request_for_quote)
{
$FormType ="forms/request_for_quote.php3";
}elseif (
$loadpage==general_enquiry)
{
$FormType ="forms/general_enquiry.php3";
}elseif (
$loadpage==ask_a_question)
{
$FormType="forms/ask_a_question.php3";
}elseif (!
$loadpage)
{
$loadpage="request_for_quote";
$FormType="forms/request_for_quote.php3";



PHP Code:
<?include("$FormType");?>



Ok put the first section of the above PHP at the top of your page, then the Javascript then create a form and stick the OPTION box in, then enter the final peice of PHP.

How it works...

Each page has it's own FORM so in effect you have two forms in one page. When the option box is used it will change the $FormType from the default to a new option and refresh the page with the new form included.

It worked for me but it may not be what you need, either way some of it may be useful.
__________________
---------------------
-- SilkySmooth --
---------------------
Proxy

Reply With Quote
  #3  
Old August 7th, 2001, 02:34 PM
Emperor Emperor is offline
Divine Wind
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Mongo
Posts: 24 Emperor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Emperor
Have a look at the double and triple combo boxes here:

http://www.wsabstract.com/script/cutindex16.shtml

I think these will do what you want as long as you are careful about the naming you should be OK. I've used the double combo script wirting to it from mySQL. I'll include the whole example (which draws out information on people and the first DDM produces the letters and the second displays the names that match the letters) although the important bit is the bit which writes the data into the javascript

PHP Code:
<FORM NAME="person_select" ACTION="whatever.php"  METHOD="GET">
<?
php

   $alphabet 
= array('A''B''C''D''E''F''G''H''I''J''K''L''M''N''O''P''Q''R''S''T''U''V''W''X''Y''Z');
   
$mysql_username "****";
   
$mysql_password "****";
   
$db_name "****";

?>
      <P><B>Author:</B><BR>
      <SELECT NAME="firstletter" SIZE="1" ONCHANGE="redirect(this.options.selectedIndex)" CLASS="input" ONFOCUS="this.className='inputOn'" ONBLUR="this.className='inputOff'">
      <OPTION SELECTED="SELECTED">Select letter:</OPTION>
<?php


   
while (list ($key$value) = each ($alphabet))
   {

   
$value trim ($value);

   echo 
"      <OPTION VALUE=\"\">$value</OPTION>\n";

   }

?>
      </SELECT>
      <SELECT NAME="person" SIZE="1">
      <OPTION SELECTED="SELECTED" VALUE=""><--Select first letter of surname</OPTION>
      </SELECT>

<SCRIPT>
<!--

/*
Double Combo Script Credit
By Website Abstraction ([url]www.wsabstract.com[/url])
Over 200+ free JavaScripts here!
*/

var groups=document.person_select.firstletter.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("<--Select first letter of surname","")

<?php

   reset 
($alphabet);

   
$db mysql_connect("localhost""$mysql_username""$mysql_password") or die ("Couldn't connect to server");
   
mysql_select_db ("$db_name",$db) or die ("Couldn't select database");

   while (list (
$key$value) = each ($alphabet)) {

     
$value trim ($value);
     
$ar1 $key "1";
     
$lc_value strtolower($value);

     
$sql "SELECT person_id, surname, initials FROM person WHERE surname LIKE '$value%' OR surname LIKE '$lc_value%' ORDER BY surname, initials, main_name";
     
$result mysql_query ($sql) or die ("Couldn't execute query");

     if (
mysql_num_rows ($result) <= 0) {
       echo 
"group[$ar1][0]=new Option(\"No entries for this letter\",\"\")\n";
     }
     else {

       echo 
"group[$ar1][0]=new Option(\"Now select author:\",\"\")\n";

       
$ar2 1;

         while (
$row mysql_fetch_array ($result)) {

echo 
"group[$ar1][$ar2]=new Option(\"$row[surname]$row[initials]\",\"$row[person_id]\")\n";

           
$ar2++;

         }
     }
     echo 
"\n";
   }

?>
var temp=document.person_select.person

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

//-->
</SCRIPT>
<INPUT TYPE="SUBMIT" NAME="submit_person" VALUE="Submit" 
    </FORM> 


If you want more than a triple combo box you should try adapting one of the existing scripts or go over to the JavaScript forum and ask them for help (or you are going about things the wrong way!!) and use the general principles outlined above to get your data into the DDMs.

Emperor

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > PHP/MySQL/JavaScript/HTML Forms Question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap