SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    North Carolina
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Adding extra fields

    I have a script that I am trying to get working in IE. It works great in Firefox, but will only work one time in IE.

    The idea is that the user is presented with a field. As soon as the user types in the field the script adds a new field under it. To keep from adding more than one field there is a variable called probURLnumKeep that gets incremented only if the field being typed in is the last field created.

    Here is the code:
    var probURLnumKeep = 1;
    function manualURL(num) {
    if (document.getElementById('problem_form')['problemURL'+num].value != '') {
    var numPlus = (1+parseInt(num));
    alert('probURLnumKeep = ' + probURLnumKeep);
    if (probURLnumKeep == num) {
    var problemURL = "problemURL"+numPlus;
    var manualURL = "manualURL('" + numPlus + "')";
    URLnum = document.createTextNode("URL " + numPlus + " ");
    bold_tag = document.createElement("B");
    bold_tag .appendChild(URLnum);

    url_input = document.createElement('INPUT');
    url_input.setAttribute("type", 'text');
    url_input.setAttribute("name", 'URL[]');
    url_input.setAttribute("id", problemURL);
    url_input.setAttribute("size", '90');
    url_input.setAttribute("onKeyUp", manualURL);
    br_tag = document.createElement('BR');

    document.getElementById('problemFields').appendChild(bold_tag);
    document.getElementById('problemFields').appendChild(url_input);
    document.getElementById('problemFields').appendChild(br_tag);

    probURLnumKeep = numPlus;
    }
    }

    The first field looks like this:
    <div id="problemFields"><b> <br>URL 1</b> <input type="text" name="URL[]" id="problemURL1" size="90" onKeyup="manualURL('1')"><br></div>

    Any help would be greatly appreciated. Like I said, it works well in Firefox, but not in IE.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have not tried this yet but dont think

    PHP Code:
    url_input.setAttribute("onKeyUp"manualURL); 
    will work in ie as its an event not attribute

    try

    *id*.onkeyup=function(){ manualURL(*whatever*); }


    also have you tought of cloning an existing input to use as the next to save code

    edit1 works in both with ammendment above
    edit2 this is the only case I have found where IE makes more sence than Moz

  3. #3
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    hi CyJobes,

    i have done small changes in your code. this is working fine in IE
    but i have not checked the browser compatibility. u can so that by any code so i have not done that. this will work fine in IE
    Code:
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
     <HTML>
     <HEAD>
     <TITLE> New Document </TITLE>
     <META NAME="Generator" CONTENT="EditPlus">
     <META NAME="Author" CONTENT="Vikrant Korde">
     </HEAD>
     
     <BODY>
     <script>
     var probURLnumKeep = 1;
     
     //this will act as a event recognizer and fake invoker - Vikrant.
     function callMe() {
     	var what = window.event.srcElement; 
     	var num = what.id.substring(10, what.id.length);
     	manualURL(num);
     }
     
     function manualURL(num) {
     	var problemForm = document.getElementById('problem_form');
     	if (problemForm['problemURL'+num].value != '') {
     		var numPlus = (1+parseInt(num));
     		if (probURLnumKeep == num) {
     			var problemURL = "problemURL"+numPlus;
     			var manualURL = "manualURL('" + numPlus + "')";
     			URLnum = document.createTextNode("URL " + numPlus + " ");
     			bold_tag = document.createElement("B");
     			bold_tag .appendChild(URLnum);
     			var url_input = document.createElement('INPUT');
     			//url_input.onKeyUp =;
     			url_input.setAttribute("type", 'text');
     			url_input.setAttribute("name", 'URL[]');
     			url_input.setAttribute("id", problemURL);
     			url_input.setAttribute("size", '90');
     			br_tag = document.createElement('BR');
     			
     			document.getElementById('problemFields').appendChild(bold_tag);
     			document.getElementById('problemFields').appendChild(url_input);
     			document.getElementById('problemFields').appendChild(br_tag);
     
     			probURLnumKeep = numPlus;
     			var urlInput = document.getElementById(problemURL);
     			urlInput.attachEvent("onkeyup", callMe, true);
     
     		}
     	}
     }
     </script>
     The first field looks like this:
     <form name="problem_form">
     <div id="problemFields"><b> <br>URL 1</b> <input type="text" name="URL[]" id="problemURL1" size="90" onKeyup="manualURL('1')"><br></div>
     </form>
     </BODY>
     </HTML>
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.


Bookmarks

Posting Permissions

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