Jump to content

echo values


alanl1

Recommended Posts

I have a function which is supoosed to show and hide dropown boxes when I tick and untick a checkbox but it is not working

 

 

function show_hide( isChecked )
{
 document.getElementById('secondDD1').style.display = ( isChecked ? 'block' : 'none' );
   document.getElementById('secondDD1').disabled = !isChecked;
 document.getElementById('thirdDD2').style = ( isChecked ? 'block' : 'none' );
 document.getElementById('thirdDD1').disabled = !isChecked;
}

 

 

<select name="<?php echo "thirdDD" .$c?>" onchange="fillSelect(this,categories[this.value],'<?php echo "thirdDD" .$counter2++ ?>')"><?php
      echo "<option selected>Please Choose</option>";
      echo "<option value='DeviceID3'>DeviceID</option>";
      echo "<option value='Product3'>Product</option>";   
      ?></select>

 

<td>
    <input type=checkbox id=cbox name=cbox value=unselected onclick=show_hide(this.checked);>One to many</td>

 

is there a way to echo out the document element values EG

 

 alert(document.getElementById('thirdDD1')) ;
 

Link to comment
https://forums.phpfreaks.com/topic/279016-echo-values/
Share on other sites

JS can "see them", just not using document.getElementById(). You need to find the elements based on the name attribute. This is where frameworks like jQuery come in handy, so you can use a simple selector, like:

 

$('select[name=thirdDD2]')...
This is of course possible with native JS, using document.querySelector(), however it's not supported in older browsers. That means to remain cross-browser compliant, you need to include some fall back code that will use document.getElementsByTagName (which is well supported) and filter out the element with the right name attribute. If you use jQuery (up to v1.9) it will provide that fall back code for you.
Link to comment
https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435456
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.