|
Posted by Nick Lazar on 01/20/06 01:34
Thanks very much for those suggestions. It's given me a few ideas that I'll
try out in the morning.
The ID does need to be unique, and although I have nothing against
JavaScript, it is quite possible that a number of the target users may have
it turned off in their browser, so my first choice is not to rely on it too
heavily, but I hadn't thought of using it for this, so will try it out....
Cheers,
Nick.
On 19/1/06 10:36 PM, in article
1137710191.286660.226560@g47g2000cwa.googlegroups.com, "Adam Plocher"
<aplocher@gmail.com> wrote:
> 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]
|