Skip to main content

Maintaining dynamic textbox control values into an array in javascript onchange event



I need to maintain text box values into an array in javascript onchange event. The text box control is created dynammically in javascript function. I have used below code. But at the end the array contains current element only. Previous values are not maintaining. How can I maintain textbox value each time entered.







<script type="text/javascript" language="javascript">

function DrawTextBox(j) {

var imgElement = document.getElementById('myimage');

var imgCoord = imgElement.getBoundingClientRect();

var cl = imgCoord.left + 20;

var x = x - cl;

var y = y - imgCoord.top;

var rect = document.getElementById(j);

if (rect == null) {

rect = document.createElement("div");

rect.id = j;

var pElement = document.getElementById("imgDiv");

pElement.appendChild(rect);

}

if (w < 0) {

w = 10;

}

if (h < 0) {

h = 10;

}

var l = parseInt(document.getElementById("hright").value) + 150 + 'px';

var style = rect.style;

// style.width = w + "px";

//style.height = h + "px";

style.left = l;

style.top = document.getElementById("htop").value;

style.backgroundColor = "Transparent";

//style.borderColor = "Blue";

style.position = "absolute";

style.borderStyle = "solid";

style.borderWidth = 2 + "px";

style.zIndex = 6000;

document.getElementById(j).innerHTML = "<textarea name=\"comments\" style=\" border:0\" Title=\"Enter Comment\" id=\"T1\" value=\"EnterComment:\" onchange=\"GetText()\" ></textarea>";

//document.getElementById(i).innerHTML = "<input type=\"Textarea\"...blah blah...></input>";

return rect;

}



function GetText() {

array1.push(document.getElementById('T1').value);

alert(array1.join(', '));

}

</script>




Comments

  1. Your question doesn´t say if/when/where array1 is declared and when DrawTextBox() is called but you can´t insert multiple elements using the same ID "T1" as it violates basic HTML rules.

    Try passing a referens to the current element like this onchange="GetText(this)" and use it in your GetText() function as;

    function GetText(el) {
    array1.push(el.value);
    alert(array1.join(', '));
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...