Jump to content

javascript focus() not working


ProblemHelpPlease

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...