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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.