简体   繁体   中英

Display more than one function value inside the same textarea

<script type="text/javascript">function TotalPrice( arg1 ) parent.document.getElementById location.search.substring(1)).value = arg1;}</script>

<script type="text/javascript"> function Misure( arg2 ){parent.document.getElementById(location.search.substring(1)).value = arg2;}</script>

I have two functions that each of them should send a value to the same textarea. The script does not take me both function values but only the last one; how can I display inside the two textarea both the values? thanks

If your functions are setting the '.value' property of the same textarea, then the whole value will be overwritten each time.

If you want to add something on to the current value of the textarea you can use the += operator, which will add the value to the current value

function TotalPrice( arg1 ) {
     parent.document.getElementById(location.search.substring(1)).value += arg1;
}

function Misure( arg2 ){
     parent.document.getElementById(location.search.substring(1)).value += arg2;
}

Your second call is overwriting the value set by the first call. If you need the args to be concatenated, you can replace node.value = arg by node.value += arg .

However, in this case, each subsequent calls argument will be added at the end of the value and you may need to clear it at some point.

 var target = document.getElementById("target"); function totalPrice(arg1){ target.value += arg1; } function misure(arg2){ target.value += arg2; } function reset(){ target.value = ""; } 
 <input id="target" /> <button onclick="totalPrice('total');">total</button> <button onclick="misure('misure');">misure</button> <button onclick="reset();">clear</button> 

If I understand correctly looks like your just replacing the initial value after your first function (if you call them sequentially). Try concatenating the textarea values in the second function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM