Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

e.srcElement is undefined in firefox?

Tags:

jquery

I am developing a website and now am testing in all browsers, I am currently testing in firefox and have found and error when using event.sourceElement?

What i need e.srcElement to do is return values, a bit below i show an example on how i get the value PropID returned.

I have written a Jquery function that uses the e.srcElement and it looks as follows:

$(function () {
        $(".DownloadLink").click(function (e) {
            e.preventDefault();

            var PropID = getParameterByName("PropID", e.srcElement.search),
                Token = getParameterByName("Token", e.srcElement.search),
                TrackingNumber = getParameterByName("TrackingNumber", e.srcElement.search);

            $.post("Valuation", { PropID: PropID, Token: Token, TrackingNumber: TrackingNumber}, function (taskId) {

                // Init monitors

                $("#dialog-modal").append($("<p id='" + taskId + "'/>"));
                updateMonitor(taskId, "Started");

                // Periodically update Modal
                var intervalId = setInterval(function () {
                    $.post("Progress", { id: taskId }, function (progress) {
                        if (progress < 50) {
                            updateMonitor(taskId, "Building File");
                        } else if (progress == 50) {
                            updateMonitor(taskId, "Uploading File to FormMobi");
                        } else if (progress >= 100) {
                            clearInterval(intervalId);
                            updateMonitor(taskId, "Complete");
                            window.location.href = "downloadcomplete";
                        }
                    });
                }, 100);
            });
        });

example of how e.srcElement works:

While testing in chrome and using the inspect element i can find that the following line returns:

Line of code:

PropID = getParameterByName("PropID", e.srcElement.search)

Returned result:

search: "?PropID=77301&Token=74d30c0e-b4ab-4164-9dfd-f35fd7091cdc&TrackingNumber=367"

And so i can get the PropID result needed.


Is there some other why for me to return the values needed? Or How can i get e.srcElement to work in fireFox?

like image 298
Pomster Avatar asked Nov 28 '12 09:11

Pomster


3 Answers

in firefox simply call e.target to work. instead of e.srcElement[which works only in IE]

like image 63
Murali N Avatar answered Nov 11 '22 01:11

Murali N


function getTarget(obj) {
    var targ;
    var e=obj;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
    return targ;
}

Will return the target for all browsers if you pass it e

from:- http://www.quirksmode.org/js/events_properties.html

like image 8
user2574579 Avatar answered Nov 10 '22 23:11

user2574579


Simple as

var val= (e.srcElement||e.target).value;
console.log(val);
like image 2
Ranjeet Rana Avatar answered Nov 11 '22 01:11

Ranjeet Rana