Page 1 of 1

convert a string and number into a string

Posted: Fri Jul 11, 2003 10:28 am
by gurjit
hi all

i have a variable called theval i pass to a function. i then loop the variable and want to add the variable i to the end of the string and represent the entire thing into a string.

i have tried eval, concentate, tostring() but nothing works.

for example i do this

<input type=checkbox id="m3" onlcick="clickall('m3')" value=1 name="lid[]">


the function does this - the problem is on line:
if (allInputs.type == "checkbox" && allInputs.id.substring(0,10) == theval+i)


the variable theval is in a string but how do i make the variable 'i' part of the string in the if statement. i have tried to set it outside and all kinds of things but it doesent happen.

ANY HELP WOULD BE APPRECIATED. BEEN WORKING ON THIS ALL DAY....DOING MY HEAD IN RIGHT NOW.





function clickall(theval) {
var allInputs = document.getElementById("form1").getElementsByTagName("input")

for (var i = 1; i < allInputs.length; i++) {
if (allInputs.type == "checkbox" && allInputs.id.substring(0,10) == theval+i) {

alert("yes")

}

}
}

Posted: Fri Jul 11, 2003 12:26 pm
by daven
if I am interepreting your question correctly:
You have 'var theval' and you want to put a counter on the end of it.
So if theval='hello' you would wind up with 'hello0', 'hello1', etc.

To do that:

Code: Select all

var theval='test_';
for(i=start;i=end;i++)&#123;
  var newval=eval(theval)+i;
  alert(newval); // test_0, test_1, test_2, etc
&#125;

Posted: Thu Jul 24, 2003 2:59 pm
by Skyzyx
Well, the way to convert a number to JavaScript is like so:

Code: Select all

var number=12345;
number=number.toString();