An ALERT stops SELECT tag from working
Posted: Sat Aug 15, 2009 7:06 pm
I ran across a strange situation that I am wondering if anyone has encountered.
I have a screen where the user is selecting a company name from a SELECT tag. When they do, a piece of javascript calls an ajax routine to fill in a DIV with the company's information. The ajax script is just plain PHP that accesses a database, pulls up the company record and echos the data to the screen.
All very straight forward and all working fine. I can keep selecting different companies from the SELECT tag, and the new info gets filled in, as expected.
Then, I went into the ajax code and added some more error checking. If an error is found, I put a message on the screen using an alert box. I do this by putting the message in a $msg variable, and then echoing out a small piece of javascript that uses alert to display the message. Looks like this:
$msg = "Something went wrong";
echo "<script type='text/javascript'>alert('$msg');</script>";
I use this method in lots of places, and I've never noticed a problem with it before (but I guess that doesn't mean there wasn't one!!).
I just noticed that as soon as I do this, my SELECT stops working. When I click on the tag, the selection box does not open, and I cannot select a different item until I leave the page and come back, or refresh the page.
As long as I don't generate an ALERT message, everything works fine. I have checked to make sure that there are no duplicate ID's names anywhere, and have run out of ideas.
Thanks for any help or direction!
I have a screen where the user is selecting a company name from a SELECT tag. When they do, a piece of javascript calls an ajax routine to fill in a DIV with the company's information. The ajax script is just plain PHP that accesses a database, pulls up the company record and echos the data to the screen.
All very straight forward and all working fine. I can keep selecting different companies from the SELECT tag, and the new info gets filled in, as expected.
Then, I went into the ajax code and added some more error checking. If an error is found, I put a message on the screen using an alert box. I do this by putting the message in a $msg variable, and then echoing out a small piece of javascript that uses alert to display the message. Looks like this:
$msg = "Something went wrong";
echo "<script type='text/javascript'>alert('$msg');</script>";
I use this method in lots of places, and I've never noticed a problem with it before (but I guess that doesn't mean there wasn't one!!).
I just noticed that as soon as I do this, my SELECT stops working. When I click on the tag, the selection box does not open, and I cannot select a different item until I leave the page and come back, or refresh the page.
As long as I don't generate an ALERT message, everything works fine. I have checked to make sure that there are no duplicate ID's names anywhere, and have run out of ideas.
Thanks for any help or direction!