Reputation: 1
i have one variable in javascript named itemid i.e. var itemid=document.getElementById('item_code').value;
in item_code there is value in this format "1025*1" and i want to display only 1025 not whole in javascript div
plz give me some idea, it is same as explode() in php but i want this in javascript to display in div
Upvotes: 0
Views: 576
Reputation: 96
This will display "1025" (will strip *1) into DIV with ID="DIV_ID":
document.getElementById('DIV_ID').innerHTML = itemid.split(/(\d+)\*\d+/)[1];
Upvotes: 0
Reputation: 19231
Use the spli method:
var itemid=document.getElementById('item_code').value.split("*")[0];
Upvotes: 0
Reputation: 887365
You're looking for the split
method.
For example:
var array = value.split('*');
var first = array[0];
Alternatively,
var first = value.substring(0, value.indexOf('*'));
Upvotes: 1
Reputation: 316969
You can use
parseInt
- Parses a string argument and returns an integer of the specified radix or base.If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.
Example:
parseInt("1025*1", 10); // 1025
Upvotes: 0