Jump to content

echo values


Go to solution Solved by 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.