Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an array from a list 1

Status
Not open for further replies.

ded

Programmer
Nov 3, 2000
41
GB
Any ideas why this will not work

Code:
var pubishArray = new Array (eval("document.eventform.pubishedid.value"));

The var contains 1,2,3,4,5 and I want an array of these items to be returned.


 
Hello,
Well, it be better to clarify your case.
I guessed the following situation:
In your textbox you have a list of values - it is actually a string and you need to use JS function split.
See

I did the following changes in your code:
<HTML>
<HEAD>
<TITLE>Script</TITLE>
</HEAD>
<BODY>
<form name=&quot;eventform&quot;>
<input type=text name=&quot;pubishedid&quot; value=&quot;1,2,3,4,5&quot;>
</form>
<script>
alert(document.eventform.pubishedid.value);
var pubishArray = document.eventform.pubishedid.value.split(',');
alert(pubishArray[0]);
alert(pubishArray[1]);
alert(pubishArray[2]);
</script>
</BODY>
</HTML>

Keep in mind that insuch way array values are strings, not integers. If you need to add some of them, youhave to use
parseInt(pubishArray[0]) + parseInt(pubishArray[2]) in order to get the integer result.

Hope this helps.
D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top