prasanth sadhana prasanth sadhana - 7 months ago 12
Javascript Question

how get all value Front and back of split function

i have one split function like



function solve() {
str1 = $('#equ').val();
var eql = str1.split(/=/g);
var lft = parseInt(eql[0]);
var rit = parseInt(eql[1]);
$('#test').text(lft+':'+rit);
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" placeholder="Enter equation" value="-5x-7=108+55" class="equ" id="equ">
<input type="submit" value="solve" class="solve" id="solve" onclick="solve()">

<p id="test"></p>





only get two value.remaining "(x-7) & +55" are missing.please help me to get all value front and back.thanks

Answer

You don't need to use parseInt(), remove it.

var lft = eql[0];
var rit = eql[1];

function solve() {
  str1 = $('#equ').val();
  var eql = str1.split(/=/g);
  var lft = eql[0];
  var rit = eql[1];
  $('#test').text(lft + ':' + rit);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<input type="text" placeholder="Enter equation" value="-5x-7=108+55" class="equ" id="equ">
<input type="submit" value="solve" class="solve" id="solve" onclick="solve()">

<p id="test"></p>