0

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

4 Answers 4

1

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('*'));
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

Use the spli method:

var itemid=document.getElementById('item_code').value.split("*")[0];

Comments

0

This will display "1025" (will strip *1) into DIV with ID="DIV_ID":

document.getElementById('DIV_ID').innerHTML = itemid.split(/(\d+)\*\d+/)[1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.