|
Posted by Adam Plocher on 01/20/06 00:36
Hmm.. you know, JavaScript could probably do all this, and that way you
could generate this value without doing a postback. You can also have
JavaScript populate a hidden form variable to send back to your
database.
Does something like this work?
Note, to test this, just put this code into a html file and type
something in the text box.. when you leave the text box it should
generate a 10 digit # that is prefixed by whatever you type into the
input box. It will also set a hidden form value, so if you were to
submit this form, php should be able to pick it up.
<html>
<script language="javascript">
function generateRandom()
{
var i = Math.round(Math.random(1000000000,9999999999) * 10000000000);
i = document.getElementById('prefix').value + i;
document.getElementById('randomValue').value = i;
document.getElementById('output').innerHTML = i;
}
</script>
<input type="text" id="prefix" onblur="generateRandom()">
<input type="hidden" id="randomValue" name="randomValue" value="">
<br /><br />
<div id="output">
<strong>Output: </strong>
</div>
</html>
I guess one problem is that it COULD theoretically duplicate an ID. It
won't be a definite unique ID. If you have to have it check against a
DB, AJAX might be the best solution, but that's a little trickier.
If it HAS to be unique, let me know and I'll help you out with an AJAX
solution.
Navigation:
[Reply to this message]
|