![]() |
window.onload question
I have the following javascript
Code:
<script language="javascript">Code:
<tr class="ocusdallergy"> Is it possible to have these rows expanded on load if the dropdown value is yes prior to a refresh/reload of the page? |
Yes, simply set the option "Yes" to selected.
<option value="Y" selected> Or another possibility Code:
function toggleRows(select, rows) {Contestant: Deadly sins. |
I think I worded my question wrong maybe. Or i am not understanding your response
The function itself works fine when a user selects yes it works wonderfully and the rows display. however upon submit it stores that value in the database. the event to display the rows is an onchange event. and when a user returns to that page it already has the yes value therefore the onchange event never happens (because the user has no need to select yes again) and the hidden rows never display. What i would like is for it to run the function on load and display any rows where the value is already yes. if i just misunderstood your answer then I apologize |
Try this - after an onchange event has occured, set the selectedIndex of the select list back to 0 in your function togglerows(). That will force the user to select an option again.
|
Change
window.onload=toggleRows();to window.onload=toggleRows; |
Phillip, That is not optimal for us because we don't want to force a user to choose something each time they log in. rather just display the results for what they have chosen previously.
Logic, I have tried that with no luck. could it be because each hidden rowset is different on the page ie. Code:
<tr class="ocusdheart"> Code:
</tr>I could be completely wrong here but wouldn't running togglerows onload not work as is because of the specifications in each line item as to what rows to unhide? How does running the javascript by itself know 1) what rows to unhide and 2) whether or not the selected value of each particular select == Y.. Would I have to run each specific onchange event onload somehow? |
Quote:
Quote:
Statements to run in your onload handler: Code:
var selects = document.getElementsByTagName( 'select' ); |
There is no need to use onload for this - just move the script to just before the </body> tag where most JavaScript belongs.
|
Code:
var selects = document.getElementsByTagName( 'select' ); |
Quote:
Code:
<script type="text/javascript"> |
Quote:
That works wonderfully.. how would i add additional box.names accommodate to more than one select on the same page?? if( box.name.indexOf( 'eReg|HRI_Diabetes' ) == 0 ) if( box.name.indexOf( 'eReg|HRI_Asthma' ) == 0 ) if( box.name.indexOf( 'eReg|HRI_Allergies' ) == 0 ) etc etc.. Or could i do something like if( box.name.indexOf( 'eReg|HRI_*' ) == 0 ) as a wildcard? all select boxes start with eReg|HRI_ |
Quote:
|
Quote:
These are the TR's that contain each of the dropdowns. Code:
<tr class="ocusddiabetes"> |
Never mind I figured it out.. I have some selects without on change events and it was ending the script.
|
Quote:
|
| All times are GMT +1. The time now is 04:47 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.