Note that there are some explanatory texts on larger screens.

plurals
  1. POadding arrays of numbers into html form input and displaying the calculated result
    text
    copied!<p>I have an array having 2-3 titles. eg. 'Get 20% Off' , 'Receive 40% Savings' , 'Grab 10% discounts' etc. I would like to get the numeric value before '%' sign. and pass this numeric value into a html form as inputs. and in return the form would calculate a percentage amount. and display all the results.</p> <p>Right now i have managed to make this work for a single title. but i am not able to get a array of titles.</p> <p>my code is as follows -</p> <p>//code for getting all the titles //putting it into an array called '$array'</p> <pre><code>foreach($array as $str) { if(preg_match('/(\d+)\%/i' ,$str,$m)) { echo $m[1],"\n"; ?&gt; &lt;?php } } ?&gt; </code></pre> <p>//the above code extracts the amount before the percentage off sign. and the below code passes it as a input to the form (name=a). and other input (name=b) is coming from a different source. thats working fine. for calculation consider that input to be 100. I would need to calculate the percent value w.r.t 100. for eg- if input a is 5, then another input b is 100. the value to be outputted would be 5.</p> <pre><code>&lt;form name="form1"&gt; &lt;input type="text" name="a" value="&lt;?php echo $m[1]; ?&gt;" size=5&gt; &lt;input class="budget-sidebar" type="text" name="b" id="amount" size=5&gt; </code></pre> <p>the below html is used for displaying the calculated value and submitting the form.</p> <pre><code>&lt;input type="text" name="total1" value="ans1" size=5 maxlength=4&gt; &lt;input type="button" value="Calculate" onClick="calc1(this.form)"&gt; &lt;/form&gt; </code></pre> <p>the below javascript function is responsible to take the inputs and calculate the value and displaying it.</p> <pre><code>&lt;SCRIPT LANGUAGE="JavaScript"&gt; &lt;!-- Begin function calc1(form) { a = form.a.value/100; b = a*form.b.value; form.total1.value = b; } // End --&gt; &lt;/script&gt; </code></pre> <p>i have posted a similar question requesting for different suggestions &amp; this is supposed to be a different query. thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload