Having a randomly generated number appear in a form field

Thanks in advance to those who can help with this!!

I have code in a php file that pulls values from a table to display in a dropdown field in a form

[php]$rarity = $dbObj->cgs(“tbl_rarity”, “”, “del_status”, “0”,“rarity_name”,"",false);
while($row_rarity = @mysql_fetch_array($rarity))
{
$rarity_id[] = $row_rarity[‘id’];
$rarity_value[] = $row_rarity[‘rarity_name’];
$rarity_min[] = $row_rarity[‘price_from’];
$rarity_max[] = $row_rarity[‘price_to’];
}
$smarty->assign(“rarity_id”, $rarity_id);
$smarty->assign(“rarity_value”, $rarity_value);
$smarty->assign(“rarity_min”, $rarity_min);
$smarty->assign(“rarity_max”, $rarity_max);[/php]

The code works fine and does what I need on the user form. There is also a field on the user form for PRICE, which is

<input type="text" name="price" id="exD_price"/>

Right now, I have to manually enter a value in that field of my choosing. The goal is to have it take the $rarity_min and $rarity_max values associated with the chosen rarity from the dropdown menu, and automatically insert a value in the price field that falls within the range of the min and max numbers, and each time I change a value in the dropdown it generates a new number and inserts it in to the price field.

In the php code I tried creating something

[php]$rprice=rand($rarity_min, $rarity_max);[/php]

and had added a value to the like value="{$rprice}", but after I select an option in the dropdown, nothing appears in the price field. I imagine there has to be an OnUpdate sort of function that needs to be called after the dropdown value is changed, but how do I do that in php?

The code works fine? I doubt it for you are using obsolete code and are suppressing errors with the @ even if you have error reporting turn on. (Again I doubt).

Here’s a good article on some new feature in php 7 and it might help you with your random number problem issue.
http://blog.teamtreehouse.com/5-new-features-php-7

However, I would address the issues that I state above first, but that is just my opinion. 8)

yes, the form works fine as it originally is. dropdowns display values correctly, and once selected, stay as they should. values entered in fields manually are fine, and when the form is submitted it adds the recotd to the table. all I am looking to do is get a field value to autopopulate from a given range based on 1 of those dropdown selections. I am not a php developer, and the syntax and logic I am used to is primarily VB, with a little java and javascript. Which is why I am here looking for PHP help. I did not create the original form, but I need to modify it.

Sponsor our Newsletter | Privacy Policy | Terms of Service