PDA

View Full Version : generate order code



syazyan
11-16-2006, 06:27 AM
hello there...i really hope that someone can help me with this code...

i have a drop down menu like this..

<select name="d_type" class="enterinput" id="d_type">
<option selected>Select Type</option>
<option value="IMG" onClick="javascript">Image</option>
<option value="STA">Statistic</option>
<option value="DIR">Director</option>
<option value="SHR">Share Holder</option>
<option value="OTH">Other</option>
<option value="OWR">Owner</option>
<option value="COL">ROC Old Name</option>
<option value="NME">ROC Name</option>
</select>

then...i need to generate the order code using the value from the drop down plus random number..such as.. IMG-1234567...

the order code will be generated once the customer choose the "d_type" from the drop down menu...

could anyone help me???

djr33
11-16-2006, 09:00 AM
Once submitted, just use:
$final = $_POST['d_type'].rand(1000000,9999999);

You can add javascript to the <select onChange...> to make it submit once an item it changed.

You might also just want to use javascript if you need realtime.

With PHP, that will need to be submitted.

Twey
11-16-2006, 06:23 PM
That looks like an order for disaster to me. The order codes must, unless they're just for show, be unique, which means storing a list of used order codes in a database and simply generating a code that's the lowest number that's not already taken.

djr33
11-16-2006, 10:45 PM
Agreed.

syazyan
11-17-2006, 01:21 AM
Once submitted, just use:
$final = $_POST['d_type'].rand(1000000,9999999);

You can add javascript to the <select onChange...> to make it submit once an item it changed.

You might also just want to use javascript if you need realtime.

With PHP, that will need to be submitted.

i need a realtime..so..could you show me the javascript??...i need to show the order code and at thesame time once the customer hit the "submit" button..the order code will be store into the database..

djr33
11-17-2006, 03:29 AM
onChange="generate(this)"

The function would be similar... something like:

function generate(x) {
x.value = x.value+random;
}

Not sure what random number functions exist for javascript. look that up.

Javascript isn't really my thing.

Also, I'd suggest what Twey is saying... makes a lot more sense. Just relying on client side scripting for order numbers is crazy... insecure, not compatible with everything AND duplicates could easily occur... etc.
Using a database and secure server side coding is a much better option.
php/mysql intro tutorial here:
http://php-myql-tutorial.com