0

I have a table with dynamically added rows that have different properties for dynamic use, submit, etc. I have one input box with a auto-complete function that has to change the rest of the input boxes values. How can change their values without a fixed name, id or class?

The dynamically created row:

<tr>
  <div id="1">
    <div id="2">
      <input type="text" name="input1" id="input1" class="input1" />
    </div>
    <div id="3">
      <input type="text" name="input2" id="input2" class="input2" onkeyup="foo(this);"/>
    </div>
  </div>   
  <input type="text" name="input3" id="input3" class="input3" />
  <input type="text" name="input4" id="input4" class="input4" />
</tr>

The JavaScript function:

foo(node){
   //node.name is input2
   change input1.value;
   change input3.value;
   change input4.value;

};

I can´t rely on static properties for the function, they have to be passed after the elements are created.

1
  • I'm trying to figure out a solution using row number Commented Oct 11, 2012 at 13:27

2 Answers 2

1

If you are open to using jQuery, you could do something like this:

$(function(){
   $("#yourTable").on("keyup","INPUT",function(){
       $("INPUT").not(this).val($(this).val());
   });
});

JSFiddle: http://jsfiddle.net/b6nDX/1/

This will make all fields change to whatever is being typed in any of the fields within the table.

NOTE: You need to narrow down the selector of course, if you wish to only use one "source" field

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but I'm not using jQuery and all the fields will receive different values.
0

This is possible trough the DOM properties.

Example:

foo(elem){
    elem.parentNode.parentNode.parentNode.parentNode.children[2].children[0].children[1].children[0].value = "";
    elem.parentNode.parentNode.parentNode.parentNode.children[5].children[0].value = "";
    elem.parentNode.parentNode.parentNode.parentNode.children[6].children[0].value = "";
    elem.parentNode.parentNode.parentNode.parentNode.children[7].children[0].value = "";
    elem.parentNode.parentNode.parentNode.parentNode.children[8].children[0].value = "";    
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.