jwk811 Posted November 20, 2010 Share Posted November 20, 2010 i have a select form. when they click a certain option a js function is used to change something. the problem is when the page is reloaded that option is automatically still selected even when i have another one auto selected. this makes it so the option that is supposed to cause a function is already selected and the function isnt done so it messes things up. how can i make it so i can change the default selected option or auto load a function if its going to be selected on refresh. (im not sure how confusing that was or not) Quote Link to comment https://forums.phpfreaks.com/topic/219267-select-form-option-auto-select-fix/ Share on other sites More sharing options...
seanlim Posted November 20, 2010 Share Posted November 20, 2010 From what I know, refreshing the page will cause form elements to return to their default values. Have you tried attaching an onload event handler? Something along the lines of: window.onload = function() {document.getElementById("select").selectedIndex = 0; } Quote Link to comment https://forums.phpfreaks.com/topic/219267-select-form-option-auto-select-fix/#findComment-1137215 Share on other sites More sharing options...
jwk811 Posted November 21, 2010 Author Share Posted November 21, 2010 no i havent that will work but is there anyway i can make it call a function if a form field is selected already on refresh if its on the one that needs a function Quote Link to comment https://forums.phpfreaks.com/topic/219267-select-form-option-auto-select-fix/#findComment-1137297 Share on other sites More sharing options...
seanlim Posted November 21, 2010 Share Posted November 21, 2010 you could technically compare it to the defaultValue of the field when the onload event is triggered.. and call the function if they are different... Quote Link to comment https://forums.phpfreaks.com/topic/219267-select-form-option-auto-select-fix/#findComment-1137333 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.