PDA

View Full Version : how to split a variable on javascript?



smansakra
11-24-2008, 10:48 AM
please look at this

on php code, i can slipt a valiable and print it:


<?php
$text="john = 34";
list($name,$age) = split("=",$text);
echo $name."'s age is ".$age;
?>


can anyone help me to split same variable on javascript?

<script type="text/javascript">
var text = "john = 34";
//--- what should i write here?--//
//--- what should i write here?--//
//--- what should i write here?--//
</script>

thanks so much

smansakra
11-24-2008, 10:56 AM
hi, i have gotten the answer

<script type="text/javascript">
var text = "john = 34";
document.write(text.split("=")[0]); // this will print "john"
</script>

thaks