www.webdeveloper.com
Results 1 to 2 of 2

Thread: Onclick and Alert Message Problem

  1. #1
    Join Date
    Mar 2011
    Posts
    9

    Onclick and Alert Message Problem

    elementClick() is called onload of body and when I click on any control on the page it is repeating the same alert message and is not showing the right control name. Any ideas?

    var s;

    function elementClick() {
    var doc = document.getElementsByTagName('form')(0);
    for (var i = 0; i < doc.getElementsByTagName('input').length; i++) {
    var c = doc.getElementsByTagName('input')(i);
    if (c.type == 'text' || c.type == 'checkbox' || c.type == 'radip') {
    c.onclick = function() { showAlert("'" + c.name + "'"); }
    var s = c.name + '\n'
    }

    }
    for (var i = 0; i < doc.getElementsByTagName('select').length; i++) {
    var c = doc.getElementsByTagName('select')(i);
    c.onclick = function() { showAlert("'" + c.name + "'"); }
    var s = c.name + '\n'
    }

    for (var i = 0; i < doc.getElementsByTagName('textarea').length; i++) {
    var c = doc.getElementsByTagName('textarea')(i);
    c.onclick = function() { showAlert("'" + c.name + "'"); }
    var s = c.name + '\n'
    }
    }

    function showAlert(text) {
    alert("'" + text + "'");
    }

  2. #2
    Join Date
    Mar 2011
    Posts
    9
    This solved the problem

    c.onclick = new Function("showAlert(" + "'" + c.name + "'" + ")");

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles