Firefox this feature

Why Firefox is not up to the challenge. This code works in IE.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<script type='text/javascript'>
function drvFunc(elem)
{
    var e = elem.name;
    var d = "document."
    var f = "frm";
    var str = d+"."+f+"."+e+".value;";
    alert(eval(str));
}
</script>
<BODY>
<form name=frm method=post>
<input type=button name=myButton id=myButton value='MyButton' onclick='drvFunc(this)'>
</form>
</BODY>
</HTML>
+3
source share
6 answers
function drvFunc(elem) {
  alert(elem.value);
}

For this function you do not need evil eval () ...

+13
source

The problem is that you have two periods: concatenation:

  • var d = "document."
  • var str = d+"."+f...

Your summary line will be: "document..frm.myButton.value;"

Delete one of the periods and it will work.

+9
source

var d = "document."

var d = "document"

eval "document..frm"

+1

. , .

function drvFunc(elem)
{
    **var e = elem.name;** <-- in firefox, this fails.  e is not initialized!! 
    var d = "document."
...
}

, , IE...

<input type=button name=1stButton id=1stButton onclick='drvFunc(this)'>
<input type=button name=2ndButton id=2ndButton onclick='drvFunc(this)'>

... drvFunc

function drvFunc(elem)
{

}
+1

:

<input type='button' name='2ndButton' id='2ndButton' onclick='drvFunc(this.id)'> 

function drvFunc(elemid){ 
   alert(document.getElementById(elemid).value); 
}
+1

You need to put quotation marks (single or double) around the attributes of your tag <input>.

Firefox probably handles unquoted attributes differently for IE: http://www.cs.tut.fi/~jkorpela/qattr.html

You also need to remove the extra point at "document.", as others have said, and you should probably reorganize drvFuncto remove eval.

The following works fine for me in Firefox 3:

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<script type='text/javascript'>
function drvFunc(elem)
{
    alert(elem.value);
}
</script>
</HEAD>
<BODY>
<form name="frm" method="post">
<input type="button" name="myButton" id="myButton" value="MyButton" onclick="drvFunc(this)">
</form>
</BODY>
</HTML>
0
source

Source: https://habr.com/ru/post/1704214/


All Articles