Jump to content

transfer the values of a generated number using jquery without refreshing page


liomon41

Recommended Posts

<!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....

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.