How to get the correct elements with elementbyid? simple correction or input should solve the failure

65 views Asked by At

What simple step is on this javascript, php, display failure missing? can't figure it out

The code is this:

 <?php $countrycode=$p["country"]; ?>
    <select size="1" name="countrycode" id="countrycode" onchange="javascript:
        if(this.value=='USA') { 
            document.getElementById('us').style.display='block';
        } else { 
            document.getElementById('us').style.display='none';
        } 
        if(this.value=='DE') {
            document.getElementById('de').style.display='block';
        } else { 
            document.getElementById('de').style.display='none';
        }
    ">
        <option value="INT" <?php 
            if($countrycode=='INT') { echo 'selected="selected"'; } ?> 
        >International</option>
        <option value="USA" <?php
            if($countrycode=='USA') { echo 'selected="selected"'; } ?> 
        >USA</option>
        <option value="DE" <?php
            if($countrycode=='DE') { echo 'selected="selected"'; } ?> 
        >DE</option>
    </select>

This is the echo (elementid ++):

in php (open php tag as: 'php' - for better reading):

php if($countrycode=='USA') { echo 'display:block;'; } else { echo 'display:none;'; } ?>" id="us"><br />Also allow: 
                <input type="checkbox" id="Targeting_CA" name="Targeting_CA" 

php if($p["CA"]=='1') { echo 'checked="checked"'; } ?> value="1">&nbsp;Canada
                &nbsp;<input type="checkbox" id="Targeting_UK" name="Targeting_UK" 

php if($p["UK"]=='1') { echo 'checked="checked"'; } ?> value="1">&nbsp;United Kingdom
                &nbsp;<input type="checkbox" id="Targeting_AU" name="Targeting_AU" 

php if($p["AU"]=='1') { echo 'checked="checked"'; } ?>  value="1">&nbsp;Australia


php if($countrycode=='DE') { echo 'display:block;'; } else { echo 'display:none;'; } ?>" id="de"><br />Also allow: 
                <input type="checkbox" id="Targeting_CH" name="Targeting_CH" 

php if($p["CH"]=='1') { echo 'checked="checked"'; } ?> value="1">&nbsp;Switzerland
                &nbsp;<input type="checkbox" id="Targeting_AT" name="Targeting_AT" 

php if($p["AT"]=='1') { echo 'checked="checked"'; } ?> value="1">&nbsp;Austria

This is what I get as result:

When it is the value 'DE' nothing appears below.

When it is the value 'USA' all (even the ones for 'DE') appears. Like this:

Also allow: Canada ¦ United Kingdom ¦ Australia display:none;" id="de"> (>> last part shouldn't be displayed - 'means display:none;" id="de">')

Also allow: Switzerland Austria (>> this should actually displays on value 'DE')

Would very appreciate a solution that is helping me out.

1

There are 1 answers

0
Starmetal On

This piece of code is correct, check if your element's ID is not spelled wrong.