liomon41 Posted March 20, 2012 Share Posted March 20, 2012 <!DOCTYPE html> <html> <head> <script> $(document).ready(function() { if($("#getPIN").click(function(){ <?php $char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $generated_password = substr(str_shuffle($char), 0, 10); ?> var genNumber; $("#txtpin").val() = genNumber; return false; })); }); </script> </head> <body> <input type = "text" name = "txtpin" id = "txtpin" value = ""> <input type = "button" name = "getPIN" id = "getPIN" value = "getPIN"> </body> </html> Hey you guys need your help... Basically what im trying to do is when the user clicks the getPIN button, the value generated using php is assigned to the txtpin textfield without refreshing the page.... thanks alot guys.... Quote Link to comment Share on other sites More sharing options...
seanlim Posted March 20, 2012 Share Posted March 20, 2012 Please make use of the code tags! This is more of a jQuery question anyway, since you've had all the PHP figured out. You don't assign anything to the val() function; instead, pass the value to the function. i.e. $(obj).val('some value'); Also, you don't need the if conditional which serves no purpose and is probably syntactically wrong too. <!DOCTYPE html> <html> <head> <script type="text/javascript"> $(document).ready(function() { $("#getPIN").click(function(){ <?php $char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890'; $generated_password = substr(str_shuffle($char), 0, 10); ?> var genNumber = '<?php echo $generated_password; ?>'; $("#txtpin").val(genNumber); return false; }); }); </script> </head> <body> <input type = "text" name = "txtpin" id = "txtpin" value = ""> <input type = "button" name = "getPIN" id = "getPIN" value = "getPIN"> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.