Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append a string value during assignment in Javascript?

Hey i dont know if that is possible but i want to set a given variable in js by reference.

What i want to do is, that each time i pass a string to the function addstring that the value of the textfield is added like +=

function addstring(string)
{
    document.getElementById("string").value = string; // its a textfield

}

How can i do that?

like image 367
streetparade Avatar asked Mar 11 '10 09:03

streetparade


2 Answers

Javascript does not support passing parameters by reference.

This link offers a good breakdown and some workarounds- Passing by Value or reference

like image 175
Morten Anderson Avatar answered Oct 14 '22 08:10

Morten Anderson


If its a reference to an input text filed then you can use the value property

function addstring(string)
{
    document.getElementById("string").value += string.value;

}

See value

like image 32
rahul Avatar answered Oct 14 '22 09:10

rahul