#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11

    onBlur="this.value=SomeJavaScriptFunction(this.value);"


    In my database I have a fields for ID and total amount of records. "A" stands for ID & "B" stands for amount

    Sample data:
    A / B
    1 / 10
    2 / 20
    3 / 30

    Now, I have these two text fields the ID & Amount.
    PHP Code:
    <input type="text" name="ID" value="<?=$ID?>" onBlur="this.value=SomeJavaScriptFunction(this.value);">
    <input type="text" name="Amount" value="<?=$Amount?>">
    How can i get the amount of each id and display it in my text field Amount? I wanted it to be like if I input ID 1 my text field ID will have the amount of 10 in text field Amount.
    Hope you get what I mean.
    Have a gr8 day
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    PHP Code:
    <input type="text" name="ID" value="<?=$ID?>" onBlur="this.form.Amount.value=this.value*10;"> 
    <input type="text" name="Amount" value="<?=$Amount?>">
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    Thanks for the piece of code. But, thats not what I want.
    What I mean is to get the amount of each ID. When I entered an ID 1 it will display the Amount recorded for that ID. Not to multiply it by 10.
    Anyway thanks. . . .
    have a great day
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    I'm not sure what you want exactly?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    Originally Posted by Drax
    What I mean is to get the amount of each ID. When I entered an ID 1 it will display the Amount recorded for that ID.

    so where is amount for each id stored? like an array or what?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    No! It's not stored in an array. As you can see with my previous question I have a sample database. Data will come from my database.

    I use onBlur to display automatically the Amount recorded for the ID.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    Originally Posted by Drax
    I use onBlur to display automatically the Amount recorded for the ID.
    OK here's my Sample Data
    "A" stands for ID & "B" stand for Amount

    A / B
    1 / 35
    2 / 23
    3 / 45

    I hope now you get what i mean
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    Originally Posted by Drax
    No! It's not stored in an array. As you can see with my previous question I have a sample database. Data will come from my database.

    I use onBlur to display automatically the Amount recorded for the ID.
    okay, i understood that from your OP...but where are you outputting the information from the database?

    can't really answer your question without the answer to this...so am i to assume that you don't know where to output your database values or what?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    Hmmm. . .
    I know where to display my output that's why I use
    Code:
    <input type="text" name="Amount" value="<?=$Amount; ?>">
    right.
    Displaying is not the problem of mine. Only the getting of data
  18. #10
  19. Cunning Linguist
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2003
    Location
    I used to live at home, now I stay at the house
    Posts
    10,180
    Rep Power
    2038
    You need to use php to put all the elements of your db in a JavaScript array, like so...
    PHP Code:
    echo '<script type="text/JavaScript">';
    echo 
    'var amounts=new Array();';
    while(
    $row=mysql_fetch_object($result))
    {
        echo 
    'amounts['.$row->ID.']='.$row->amount.'\n';

    Or something like that.
    Then you can use JS to assing the correct value from the array...
    Code:
    <input type="text" name="ID" value="<?=$ID?>" onBlur="this.form.elements['Amount'].value=amounts[this.value];">
    <input type="text" name="Amount" value="<?=$Amount?>">
    That should do it.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    Originally Posted by Drax
    Hmmm. . .
    I know where to display my output that's why I use
    Code:
    <input type="text" name="Amount" value="<?=$Amount; ?>">
    right.
    Displaying is not the problem of mine. Only the getting of data
    you totally misunderstood me.



    chief, that's what i was working on...i am glad i noticed your post before i bothered posting....
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    Thanks for the code pal. It work just fine
    Have A great day & GOD bless.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    78
    Rep Power
    11
    Sory pal I misunderstand you. Anyway I got your point.Thanks for the code pal. It works just fine
    Have A great day & GOD bless.

IMN logo majestic logo threadwatch logo seochat tools logo