javascript confirm dialog issues
I have some troubles with confirm dialog not working with Firefox, but working with Chrome.
html code looks like this:
<input type="submit" name="Odjava" value="Remove selected link" onclick="return odjava(somelink,'Do you really want to remove ')"/>
javascript code looks like this:
function odjava(link,text)
{
if(link=="" || text=="")
return false;
return confirm(text + link + " ?");
}
With Chrome, everything is ok - onClick generates "confirm" dialog, and if user answer with "yes", form is submitted, otherwise it's not. Firefox doesen't show "confirm" dialog, it just submits the form.
Why's that? What am i doing wrong?
****EDIT: I got it! I just changed my javascript to look like this:
function odjava(text)
{
var linkovi = document.getElementById('linkovi');
link = linkovi.options[linkovi.selectedIndex].text
if开发者_如何学C(link=="" || text=="")
return false;
return confirm(text + link + " ?");
}
and it's working. It turn out that Chrome can find element in document even without document.getElementById, FF can't (won't)!
Is somelink
defined safely in both Firefox and Chrome?
When I try your code it works successfully in both FF and Chrome if someLink
is defined, and fails to work as you describe in both if it is not defined.
Never seen this before, but did a bit of googling, and came up with the following: http://www.tek-tips.com/viewthread.cfm?qid=1431250&page=10
Seems a little hokey to me, but thought I would point it out anyway. Looks like they recommend putting an extra "return false;" in the onclick after the function call.
精彩评论