SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,096
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Problem in retrieving value

    Hi, I need some help for this onclick function, my problem is that i could not get the exact value returned by the ajax.
    for example the value should be like this
    000005
    when i tried to alert, it will only gives me 5 not 000005

    Code:
    $(function(){
       $.ajax({
           type: 'post',
           url: 'to_other_page.php',
           data: {id:id},
           success: function(data){    
              some code here...
        
          } 
       });
      
    });
    
    
    function LoadMyData(idx){
       alert(idx);
        $.ajax({
           type: 'post',
           url: 'Studentpage.php',
           data: {id:idx},
           success: function(data){    
              some code here...
        
          } 
       });
       
      
    }
    here is the separate file,
    this is where i am going to use the onclick function

    to_other_page.php

    let's just assumed that i have successfully queried the student table.
    Code:
        
       $query = mysql_query('select * from student');
       while ($row = mysql_fetch_array( $query))  {
       <tr onclick="LoadMyData('.$row['std_id'].')">
                                    <td >$row['std_id']</td>
                                     <td >$row['std_name']</td>
                                    
                           </tr>
     }
    when i opened the console in firebug i can see that the inside of my function is 000005
    but when it returned to other page it will only alert 5.

    can you please help me what is wrong with this.

    Thank you in advance.

  2. #2
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,272
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    At least someone didn't think the number was octal.

    Actually, with 5, it could have been... javascript does, anyway, but I dunno about browsers themselves.

    Anyway, are you doing math with this number? If so, make sure nobody mistakes it for octal: do a parseInt(000005, 10) (this gives you 5 but it means when your next number is 000031 it won't be interpreted as, say, 25).
    Or, force it into a string. Wrap quotes around it or something. If you're not mathing with it.


    if the formatting is super-important for your users, you could use a little function that manually adds one or more zeros (as strings) to your number, before presenting to the user.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •