ProblemHelpPlease Posted March 4, 2011 Share Posted March 4, 2011 I am using the focus() command to select a text field on completion of a XMLHttpRequest which send data back to the page. It was working fine until I added the code for a sound file in the data that is returned and now the focus() is no longer selecting the text field. It appears that playing the sound is removing focus from the text field to the sound. Any ideas as to how to get round this. Link to comment Share on other sites More sharing options...
thescientist Posted March 4, 2011 Share Posted March 4, 2011 is the focus even coming after the sound line? Perhaps some code would help us get a better understanding of the situation. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted March 4, 2011 Author Share Posted March 4, 2011 The code is 3 seperate files which is why I didnt post it. If I remove the sound code then it works ok and then fails if I put it back in.Code passed back from external PHP that is accessed from main PHP file via xml. <span style=\"font-weight:bold; color:red;\">No product matches that barcode, product has not been added.</span><br><br><embed src=\"failure.wav\" height=\"0\" width=\"0\" volume=\"7\"> Javascipt line that sets the focus, part of an external JS file that does some other things not related to this. I dont get any JS errors showing. document.getElementById("loadproductid").focus(); The embed code is passed back to the JS file which then updates the first PHP page setting the focus and playing the sound. I also tried adding an inline JS after the embed code to make sure that it happened after the file played but it made no difference. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2011 Share Posted March 4, 2011 I think he was asking if you are focusing the element before or after adding the sound to the page. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted March 4, 2011 Author Share Posted March 4, 2011 I thought I answered that in the last paragraph. I have tried before and after with no difference.This JS adds the embed to the page and happens in the same section of code as the focus. Changing the order of these makes no difference to the problem document.getElementById("liveresult").innerHTML=xmlhttp.responseText; Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted March 5, 2011 Author Share Posted March 5, 2011 Maybe I need to use the JS script to play the file rather than add the code for an embed that plays automatically. Is this possible with JS? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 5, 2011 Share Posted March 5, 2011 You can create an embed element and add it to the DOM, but it's probably going to have the same behavior. Link to comment Share on other sites More sharing options...
ProblemHelpPlease Posted March 5, 2011 Author Share Posted March 5, 2011 Problem SolvedI have added a timeout that waits for the sound file to finish playing before setting the focus() and it now works perferctly. setTimeout("document.getElementById('loadproductid').focus()",3000); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.