Hi
I have below code . When alert is uncommented the focus is on first column otherwise no.
***********************
*
Thanks
Uday DodiyaPosted Sep 7, 2024, 9:42 AM
Hi Ramco,
There is following possibility, please check
1.Check if empCodeField is Found: Add a console.log(empCodeField); before calling empCodeField.focus() to see if it's null or defined.
2. Use window.onload Correctly: Make sure that the window.onload function is executing only after all elements are loaded. You can also add a console log to check if the element is correctly found.
3. Place Script at the End of the Body: Moving your script to the end of the body ensures that all elements are rendered before your script executes.
4. Use document.addEventListener("DOMContentLoaded", function() {...});: This event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.
Code :
Ramco RamcoPosted Sep 6, 2024, 11:53 AM
Hi Naimish
Written below code but not working still.
Thanks
Naimish MakwanaPosted Sep 6, 2024, 11:49 AM
Try this script
Thanks
Ramco RamcoPosted Sep 6, 2024, 11:38 AM
Hi Naimish
Even now it is also not working. I am attaching full Aspx page
Thanks
Naimish MakwanaPosted Sep 6, 2024, 11:29 AM
It seems like the focus issue is related to the timing of when the
focus()method is called. When thealertis uncommented, it delays the execution of thefocus()method, allowing the DOM to fully load. Without thealert, thefocus()method might be called before the DOM is fully ready.To fix this, you can use the
setTimeoutfunction to delay the focus call slightly, ensuring the DOM is fully loaded:This should ensure that the focus is set on the
txtEmployeeCodefield regardless of thealert.Thanks