close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Having the child feed the parent - help with Dynamic Dropdowns

Thread began 9/17/2015 8:50 am by Nathon Jones Web Design | Last modified 9/30/2015 10:51 am by Nathon Jones Web Design | 3203 views | 12 replies

Nathon Jones Web Design

Below, thank you.

Here's what I have on that page:

<script>
function getCountryData(list) {
var listOption = list.options[list.selectedIndex];
var countryID = listOption.getAttribute("data-country-id");
var countryName = listOption.getAttribute("data-country");
document.getElementById("tmsacountryID").value = countryID;
document.getElementById("showCountry").innerHTML = countryName;
}
</script>

<div class="form-group">
<label for="tmsaregionID" class="col-sm-2 control-label">Region:</label>
<div class="col-sm-6">
<select id="tmsaregionID" name="tmsaregionID" class="form-control" onchange="getCountryData(this)">
<option value="0">Please select</option>
<?php
while(!$rsREGIONS->atEnd()) {
?>
<option value="<?php echo($rsREGIONS->getColumnVal("tmsaregionID")); ?>" data-country-id="<?php echo($rsREGIONS->getColumnVal['tmsacountryID']); ?>" data-country="<?php echo($rsREGIONS->getColumnVal['tmsacountry']); ?>"><?php echo($rsREGIONS->getColumnVal("tmsaregion")); ?></option>
<?php
$rsREGIONS->moveNext();
}
$rsREGIONS->moveFirst(); //return RS to first record
?>
</select>
</div>
</div><!-- end form-group -->

<div class="form-group">
<label for="tmsacountryID" class="col-sm-2 control-label">Country:</label>
<div class="col-sm-6">
<span id="showCountry"></span>
<input type="text" class="form-control" id="tmsacountry" name="tmsacountry" readonly>
<input type="text" id="tmsacountryID" name="tmsacountryID" value="">
</div>
</div><!-- end form-group -->



I changed this in your example:
document.getElementById("countryID").value = countryID;

To this...
document.getElementById("tmsacountryID").value = countryID;

..as I felt that must match the id of the form field. I've un-hidden them as well just so I can check they're working correctly.
Also, whilst I understand that <span id="showCountry"></span> will (should) display the country name, how do I get that value into my readonly form field?

Really appreciate the help, thank you. Was messing about with dynamic dropdowns for aaages before you pointed out the obvious!
NJ

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...