Reputation: 18876
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>
Upvotes: 0
Views: 543
Reputation: 11461
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.
Upvotes: 1