SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: replace problem

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace problem

    hi
    i have this piece of code
    Code:
    function getValInp(obj) {
    VAry = new Array();
    vObj = obj.getElementsByTagName("input");
    for (i = 0; i < vObj.length; i++) {
      VAry[i] = vObj[i].value;
    }
    for (i = 0; i < vObj.length; i++) {
    if(vObj[i].type.toLowerCase() == "hidden") {
      obj.innerHTML = obj.innerHTML.replace('hidden">', 'hidden" value=\"'+VAry[i]+'\">');
    }
    if(vObj[i].type.toLowerCase() == "text") {
      obj.innerHTML = obj.innerHTML.replace('text">', 'text" value=\"'+VAry[i]+'\">');
    }
    }
    return obj.innerHTML;
    }
    the part where are hidden fields works perfectly but...
    the part where are text fields wont work or it replace in other way...
    for example i expect type="text" value="something" and i get value="something" type="text"..
    as u can see the output is in the other way?
    and if there is another text field it wont work...
    any help or suggestion appreciated..
    thanx in advance...

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem solved...
    forgot to pass obj.innerHTML to a variable

    thanx anyway
    cheers

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see that you set both the hidden and text fields to the same value, why not simplify it a bit:
    Code:
    for (i = 0, oElement; oElement = vObj[i]; i++) {
    	if(oElement.type == "hidden" || oElement.type == "text") {
    	  oElement.value = VAry[i];
    	}
    }


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
  •