0

On page load I would like jquery to load the UUID method as a value to the UUID field so that I see it passed as a parameter on submit. This and this SO post helped, but Im still not getting there...

<FORM ACTION="urlAuction.html" METHOD=GET>
 <INPUT TYPE=TEXT NAME="url">
 <INPUT id="uuid" TYPE=TEXT NAME="uuid" VALUE="" >
 <INPUT TYPE=SUBMIT VALUE=Submit>
</FORM>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript"> 
 $(document).ready(function() {
     var $uuid = $('#uuid'); 
         $uuid.val(GUID());
 });
 function GUID ()
 {
  'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
      return v.toString(16);
 });
}
</script>
1
  • 2
    That function belongs in a game of code golf. Commented Feb 2, 2013 at 4:16

1 Answer 1

1

Your GUID function lacks a return to return the value it produces for you:

 function GUID ()
 {
     return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c)
     {
        var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
     });
 }

It looks like it returns something the way you formatted the braces, but in fact the return v.toString(16) belongs to the anonymous callback function being used by replace to populate each digit with a random hexdecimal digit.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.