how to trim a text and get the data after the colon(:) and eliminate space

example:
        5 Gallon Qty: 10

adn then on dropbox selected the the value of quantity textbox will be the trim part 10

Recommended Answers

All 11 Replies

I assume that ur string have only one colon, and next to colon is the text u need to find

$fullstr="   5 gallon qty: 10";
$strarr=explode(":",$fullstr)
echo "qty=".trim($strarr(1));

it's not working

        function Price(data) {

        document.getElementById("productprice").value = data.options[data.selectedIndex].id;

        newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
        document.form.total.value = newValue;


        $fullstr="document.getElementById("product").innerHTML";
        $strarr=explode(":",$fullstr)
        document.form.quantity.value = trim($strarr(1));
        }

You posted in php, so I replied php code, and the code you have written is in javascript. Now Following is the javascript code.

    function Price(data) {

    document.getElementById("productprice").value = data.options[data.selectedIndex].id;

    newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
    document.form.total.value = newValue;

    var str=document.getElementById("product").innerHTML;
    var n=str.split(":");

    document.form.quantity.value = n[1];
    }

on dropdown onchange it wont show the trim data on quantity textbox help pls

<select name="product" id="product" onchange="Price(this)">
    <option value="" disabled="disabled" selected="selected">Please select a product</option>
    <?php
    foreach ($product as $product) {
    ?>
    <option value="<?php echo $product['Product']?>" id="<?php echo $product['Price']?>"><?php echo $product['Product'] . " Qty: " . $product['Quantity']?></option>
    <?php
    }
    ?>
    </select>

    <input type="text" name="quantity" />

send me html code

tnx in advance

    function Price(data) {

    document.getElementById("productprice").value = data.options[data.selectedIndex].id;

    newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
    document.form.total.value = newValue;

    var w = document.getElementById("product").selectedIndex;
    var str=document.getElementById("product").options[w].text;

    var n=str.split(":");

    document.form.quantity.value = n[1];
    }

still not showing

Actually I wanted your html code ,
you run ur page, then right click, view source, copy that source and paste it here

<html>
<head>
<title>Delivery</title>

        <script src="js/margz.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/application.js" type="text/javascript" charset="utf-8"></script> 
        <link rel="stylesheet" type="text/css" href="style.css" />
        <link rel="shortcut icon" href="favicon.gif">
        <script type="text/javascript" src="js/jquery.js"></script> 
        <script type="text/javascript" src="js/jquery.validate.js"></script> 
        <script language="javascript" src="js/cal2.js"></script>
        <script language="javascript" src="js/cal_conf2.js"></script>

        <script type="text/javascript">


        function Price(data) {


        document.getElementById("productprice").value = data.options[data.selectedIndex].id;
        newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
        document.form.total.value = newValue;
        var w = document.getElementById("product").selectedIndex;
        var str=document.getElementById("product").options[w].text;
        var n=str.split(":");
        document.form.quantity.value = n[1];
        }

        function computetotal() {

        newValue = (parseInt(document.form.price.value) * parseInt(document.form.deliver.value)); 
        document.form.total.value = newValue;

        }


        function computecustody() {

        newValue = (parseInt(document.form.deliver.value) - parseInt(document.form.return.value)); 
        document.form.custody.value = newValue;

        }

        function computecharge() {

        newValue = (parseInt(document.form.cash.value) - parseInt(document.form.total.value)); 
        document.form.charge.value = newValue;

        }

        function computequantity() {

        newValue = (parseInt(document.form.deliver.value) - parseInt(document.form.quantity.value)) + parseInt(document.form.return.value); 
        document.form.cquantity.value = newValue;

        }

            $('document').ready(function(){

            $('#form').validate({
                    rules:{
                        "tror":{
                            required:true,
                            number:true,
                            maxlength:40
                        },

                        "name":{
                            maxlength:40
                        },
                        "price":{
                            required:true,
                            number:true
                        },
                        "deliver":{
                            required:true,
                            number:true
                        },
                        "return":{
                            required:true,
                            number:true
                        },
                        "total":{
                            required:true,
                            number:true
                        },
                        "date":{
                            required:true
                        }},

                    messages:{
                        "tror":{
                            required:"tror field is required",
                            number:"Please enter a valid number"
                        },
                        "price":{
                            required:"Price field is required select product first",
                            number:"Please enter a valid number"
                        },
                        "deliver":{
                            required:"Deliver field is required",
                            number:"Please enter a valid number"
                        },
                        "return":{
                            required:"Return field is required",
                            number:"Please enter a valid number"
                        },
                        "total":{
                            required:"Total field is required",
                            number:"Total must be a valid number"
                        }},

            })

        });
        </script> 
        <style type="text/css">
        .error{
        font-family:Arial, Helvetica, sans-serif;
        color:#FF0000;
        font-size:10px;
        padding-left:10px;
        }
        </style>
</head>



<body>

<div id="main_container">
    <div id="header">
        <div class="logo"><img src="images/logo.png" width="150px" height="100px" /></div>      
    </div>
        <div class="menu">
            <ul>                                                                         
                <li><a href="inventory.php">Inventory</a></li>
                <li><a href="walkin.php">Walk In</a></li>
                <li><a href="dealer.php">Dealer</a></li>
                <li class="selected"><a href="delivery.php">Delivery</a></li>
                <li><a href="logout.php">Log Out</a></li>
                <li><input type="text" style="height:42px;" name="filter" placeholder="Search" value="" id="filter" /></li>
            </ul>
        </div>

    <div class="center_content">

    <div class="title">DELIVERY</div>

<form name="form" id="form" action="" method="post">
<br />
<table width="449" border="0">
<thead>
  <tr>
    <td width="107">TR/OR: </td>
    <td width="326"><input type="text" name="tror" maxlength="4" /></td>
    </tr>
  <tr>
    <td> Customer's Name: </td>
    <td><input type="text" name="name" maxlength="40" /></td>
    </tr>
      <tr>
   <td> Product: </td>
    <td>
    <select name="product" id="product" onchange="Price(this)">
    <option value="" disabled="disabled" selected="selected">Please select a product</option>
        <option value="10 Lit" id="10">10 Lit Qty: 5</option>
        <option value="5 G" id="30">5 G Qty: 20</option>
        <option value="ChocoChoco" id="5">ChocoChoco Qty: 100</option>
        </select>
    </td>
    </tr>
    <tr>
  <tr>
    <td> Price: </td>
    <td><input id="productprice" onchange="computetotal" readonly type="text" name="price" /></td>
    </tr>
  <tr>
    <td> Deliver: </td>
    <td><input type="text" onchange="computecustody();computetotal();computequantity();" name="deliver" /></td>
    </tr>
  <tr>
    <td> Return: </td>
    <td><input type="text" onchange="computecustody();computetotal();computequantity();" name="return" /></td>
    </tr>
  <tr>
    <td> Custody: </td>
    <td><input readonly type="text" name="custody" /></td>
    </tr>
      <tr>
    <td> Total: </td>
    <td><input readonly type="text" onchange="computecharge()" name="total" /></td>
    </tr>
    <tr>
    <td> Cash: </td>
    <td><input type="text" onchange="computecharge()" name="cash" /></td>
    </tr>
    <tr>
    <td> Charge: </td>
    <td><input readonly type="text" name="charge" /></td>
    </tr>
  <tr>
    <tr>
    <td></td>
    <td><input type="text" name="quantity" /><input readonly type="text" name="cquantity" /></td>
    </tr>
  <tr>
    <td></td>
    <td>
    <input type='text' name='date' hidden readonly value='2013/03/24' /> </td>
    </tr>
    <tr>
    <td></td><td><input type="submit" name="Add" value="Add"></td>
    </tr>
</thead>
</table>
</form>





<table>
<thead>
<tr>
<th>TR/OR</th>
<th>Customer's Name</th>
<th>Product</th>
<th>Price</th>
<th>Deliver</th>
<th>Return</th>
<th>Custody</th>
<th>Cash</th>
<th>Charge</th>
<th>Delete</th>
<th>Update</th>
</thead>
</tr>
<tr>
<td>1111</td>
<td>qqqq</td>
<td>10 Lit</td>
<td>10</td>
<td>10</td>
<td>10</td>
<td>0</td>
<td>100</td>
<td>0</td>
<td><a href="deliverydelete.php?tror=1111 ">Delete</a></td>
<td><a href="deliveryupdate.php?tror=1111">Edit</a></td>
</tr>


<tr>
<td>1231</td>
<td>margz</td>
<td>10 Lit</td>
<td>10</td>
<td>11</td>
<td>5</td>
<td>6</td>
<td>110</td>
<td>0</td>
<td><a href="deliverydelete.php?tror=1231 ">Delete</a></td>
<td><a href="deliveryupdate.php?tror=1231">Edit</a></td>
</tr>


<tr>
<td>2222</td>
<td>mmmmmm</td>
<td>5 G</td>
<td>30</td>
<td>30</td>
<td>30</td>
<td>0</td>
<td>1000</td>
<td>100</td>
<td><a href="deliverydelete.php?tror=2222 ">Delete</a></td>
<td><a href="deliveryupdate.php?tror=2222">Edit</a></td>
</tr>


</table>

</div>    


    <div id="footer">                                              
        <div class="left_footer">Copyright Margz 2013</div>
    </div>



</div>
<!-- end of main_container -->

</body>
</html>

There are others problems in your, first you can not use "return" as name of any html item, its gives error
second you dont have any bottles html anywhere, so in price function I commented first 3 lines to test my code.

function Price(data) {

//document.getElementById("productprice").value = data.options[data.selectedIndex].id;

//newValue = (parseInt(document.form.bottles.value) * parseInt(document.form.price.value)); 
//document.form.total.value = newValue;

var w = document.getElementById("product").selectedIndex;
var str=document.getElementById("product").options[w].text;

var n=str.split(":");

document.form.quantity.value = n[1];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.