Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

dynamically changing dropdown caption based on drop down selection

Posted on 2005-04-13
6
Medium Priority
?
243 Views
Last Modified: 2010-05-18
Hello everyone,

I am trying to set this up so that when I change the main dropdown (lstMake) that the text for the caption in front of the second drop down changes automatically based on the selection from the first.  I am using a slightly modified version of this code.

http://www.ashleyit.com/forums/list.php?6

What I want to be able to do is not pass the caption with the selectbox call but have it in the HTML as a DIV tag I think it is called but i can't seem to get it working.   I think it is because the javascript call creates the box dynamically, not sure though.  If I put another dropdown box in and change the doIt function it works but I want to tie it into the code to dynamically populate the other drop downs.

Here is my code.

<html>
<head>
  <title>JSRS Select Demo</title>
  <script language="javascript" src="jsrsClient.js"></script>
  <script language="javascript" src="selectphp.js"></script>

<script>
function doIt(theForm){
//set ARRAYS
  var names = new Array('Canada','United States');
  var pagerType = new Array('alpha', 'alpha', 'numeric', 'numeric');
//set other variables
  var arrayPos;
  var theSelect = theForm.lstMake

  var theDiv = document.getElementById('dynArea');
password=prompt("That's a password-check with an Inputbox", "Enter password here");
//if the user did not select the "Select Someone" option
 if(theSelect.value != 0){
  //find out whose name was selected and save that i value
    for(i=0;i<names.length;i++){
       if(names[i] == theSelect[theSelect.selectedIndex].text)
             arrayPos = i;
     }

  //write the new form element to the div
     if(names[arrayPos] == 'United States')
        theDiv.innerHTML = 'State:'
     else
        theDiv.innerHTML = 'Prov:'
 }
 
//the user selected the "Select Someone" option so we clear the div
 else
   theDiv.innerHTML = ''
}
</script>


  <style>
    </style>
</head>

<?php
  $make = isset($_POST['lstMake']) ? $_POST['lstMake'] : -99;
  $model = isset($_POST['lstModel']) ? $_POST['lstModel'] : -99;
  $options = isset($_POST['lstOptions']) ? $_POST['lstOptions'] : -99;
?>
<body onload="preselect('<?php echo $make;?>', '<?php echo $model;?>', '<?php echo $options;?>', 1);" onhelp="jsrsDebugInfo();return false;">
<h2></h2><table width=500 align=center cellpadding="0" cellspacing="0">
 
    <TD align=center>
<form name="QForm" method="post" action="Advance.php">

          <table width="500" border="0" cellspacing="0" cellpadding="0">
            <tr></tr>
              <td width="359"><table align=center width=359>
                  <tr>
                          <img src="newversion/images/finahome.gif">
                    <td width="55"><font color="#333333" size="3" face="Tahoma, Verdana, Arial, Helvetica, sans-serif"></font>Country:</td>
                    <td width="287"><?  SelectBox ("",    "lstMake","onChange='doIt(this.form)'"); ?></td>
                  </tr>
                  <tr>
                    <td><div id="dynArea"></div></td>
                    <td>
                      <? SelectBox ("",   "lstModel", ""); ?>
                    </td>
                   
                  </tr>
                  <tr>
                    <td>City:</td>
                    <td colspan=2>
                      <?SelectBox ("", "lstOptions", ""); ?>
                    </td>
                  </tr>
                  <tr>
                    <td colspan=2><input type=submit name=s1 value="Search Listings">
                    </a>                    </td>
                  </tr>
                </table>                </td>
              <td width="172"><img src="images/pic3.jpg" width="172" height="160"></td>
            </tr>
          </table>
</form>
       
    </TD>
  </TR>
  <tr>
    <TD align=center class=TitleLinks><div align="left">
        <hr size="1">
        <img src="newversion/templates/images/private.gif" width="327" height="33">
      </div></TD>
  </TR>
  <tr>
    <TD align=center class=TitleLinks><div align="center">
        <table width="394" border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td width="394">For Sale by Owner homeowners can enjoy listing their
              home on the market with our friendly private lisitings service to
              list property quickly and easily.</td>
          </tr>
        </table>
        <br>
      </div></TD>
  </TR>
  <tr>
    <TD align=center class=TitleLinks><div align="left">
        <hr size="1">
        <img src="newversion/templates/images/realtor.gif" width="209" height="33">
      </div></TD>
  </TR>
  <tr>
    <TD align=center class=TitleLinks> <table width="394" border="0" cellspacing="0" cellpadding="2">
        <tr>
          <td width="394">Realtors can benefit in additional features not included
            in our private listings. Register as a realtor and receive your Realtor
            webpage. </td>
        </tr>
      </table></TD>
  </TR>
</table>
  <tr ALIGN="LEFT">
    <td width="15%">&nbsp;</td>
    <td align="left">&nbsp;
    </td>
  </tr>
<?php

function SelectBox( $Label, $selectName , $event){
  ?>

<?php echo "<style='font-size: 7pt;'>", $Label, "</style>" ?><select name="<?php echo $selectName ?>" <? echo $event ?> style="font-size: 7pt;">
        <option></option><option></option><option></option>
        <option>--------- Not Yet Loaded ---------</option>
      </select>
<?php
}
?>





Any help would be appreciated.  Thanks in advance


0
Comment
Question by:mitai
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13779773
Did you mean to post this Q in the PHP area?

This is JSP...
0
 

Author Comment

by:mitai
ID: 13782556
yeah, but it is javascript that I am looking for.  see function doIT
0
 
LVL 8

Accepted Solution

by:
koppcha earned 1000 total points
ID: 13793188
I did similar stuff in JSP since it involves javascript this is what i figured out .
Below part should be changed

From
>//find out whose name was selected and save that i value
    for(i=0;i<names.length;i++){
       if(names[i] == theSelect[theSelect.selectedIndex].text)//options is not chosen
             arrayPos = i;
     }


To
>//find out whose name was selected and save that i value
    for(i=0;i<names.length;i++){
       if(names[i] == theSelect.options[theSelect.selectedIndex].text)//options is not chosen in old version
             arrayPos = i;
     }
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13793194
May be it could be of some help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’m willing to make a bet that your organization stores sensitive data in your Windows File Servers; files and folders that you really don’t want making it into the wrong hands.
Ready to kick start your career in 2018? Add app developer skills to your resume. January’s Course of the Month features Android App Development training with hands-on learning.  Read on to learn why these skills are important.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question