alanl1 Posted June 10, 2013 Share Posted June 10, 2013 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')) ; Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/ Share on other sites More sharing options...
nogray Posted June 11, 2013 Share Posted June 11, 2013 You can just do alert(document.getElementById('thirdDD1').value) ; assuming thirdDD1 is an input, select or textarea. Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435425 Share on other sites More sharing options...
ginerjm Posted June 11, 2013 Share Posted June 11, 2013 You haven't assigned an id value to the dropdowns. JS can't see them. Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435430 Share on other sites More sharing options...
alanl1 Posted June 11, 2013 Author Share Posted June 11, 2013 how do i actually assign a value to it for js to see Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435435 Share on other sites More sharing options...
Adam Posted June 12, 2013 Share Posted June 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435456 Share on other sites More sharing options...
Solution alanl1 Posted June 12, 2013 Author Solution Share Posted June 12, 2013 thanks adam got it now Quote Link to comment https://forums.phpfreaks.com/topic/279016-echo-values/#findComment-1435458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.