#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15

    Where do i place this?


    Hi,

    i have a cript which allows users to edit their information. I can make the form edit and update the data, but when the user returns to the form to update the information, it retunrs to the first value.

    I am not sure where to place this tag <?=$a13?>

    PHP Code:
    <select name="quals" >
            <
    option value="Diploma">Diploma</option>
            <
    option value="Certificate">Certificate</option>
            <
    option value="License">License</option>
            <
    option value="In School">In School</option>
         </
    select
    I have another field which works fine:

    PHP Code:
    <textarea name=SK_d cols=35 rows=6 id="SK_d"><?=$a11?></textarea>
    Any ideas what im doing wrong?

    Comments on this post

    • chadsmith729 agrees : Drive By Rep! {BLAP!} You've been hit!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Location
    West Yorkshire, England
    Posts
    233
    Rep Power
    20
    There is a field in the option tag called selected. You need to set it to selected when the appropriate option is written. IE: if $a13 equals "License", then the license option field would read
    PHP Code:
    <option value="License" selected="selected">License</option
    The easiest way to do this is to check the value of $a13 and write selected="selected" when the value is correct for the current option
    PHP Code:
    <option value="License"<?php if(strcasecmp($a13,"license") == 0) print(' selected="selected"');?>>License</option>
    Hope this helps.

    Comments on this post

    • chadsmith729 agrees : Drive By Rep! {BLAP!} You've been hit!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    So i need to make all of them selected like this:

    PHP Code:
    <select name="quals"  >
            <option value="Diploma" selected>Diploma</option>
            <option value="Certificate" selected>Certificate</option>
            <option value="License" selected>License</option>
            <option value="In School" selected>In School</option>
           <?=$a13?>
          </select>
    Last edited by toolman; April 30th, 2006 at 11:59 AM.
  6. #4
  7. No Profile Picture
    I AM A GOLDEN GOD
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Apr 2003
    Location
    Camarillo, California
    Posts
    5,929
    Rep Power
    1170
    Here's how I'd do it -
    PHP Code:
    <select name="quals">
    <?php
    $quals_options
    = array('Diploma','Certificate','License','In School');
    foreach ( 
    $quals_options AS $value )
    {
        
    // start the option element, insert the current value
        
    echo "<option value='{$value}' ";

        
    // ternary operator logic determines which element is selected
        
    echo ( !empty($a13) && $value == $a13 ) ? 'SELECTED' '';

        
    // close the option element, display the value to the enduser
        
    echo ">{$value}</option>\n";
    }
    ?>
    </select>
    Simple, you can change the elements quickly by your array $quals_options, plus it gives you the ability to pull the data from a database or flatfile and loop through quickly to make the select element structure.

    Comments on this post

    • toolman agrees : Excellent support!
    • chadsmith729 agrees : Drive By Rep! {BLAP!} You've been hit!
    Last edited by lnxgeek; April 30th, 2006 at 12:01 PM.
    "Seriously, we're not a search engine, we're actual people." ~ ManiacDan

    BookMooch.com : Give books away. Get books you want.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    thanks. It works and updates the info, but when the user retunrs to the edit page, it still goes to 'Diploma' which is the first option, not the newly edited one.
    Last edited by toolman; April 30th, 2006 at 12:06 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Location
    West Yorkshire, England
    Posts
    233
    Rep Power
    20
    Originally Posted by toolman
    So i need to make all of them selected like this:
    No, just the one you want selected, like this:
    PHP Code:
    <select name="quals"  >
            <
    option value="Diploma">Diploma</option>
            <
    option value="Certificate">Certificate</option>
            <
    option value="License" selected>License</option>
            <
    option value="In School">In School</option>
          </
    select
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    Excellent. Got it all working! Many thanks!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    I have another problem now.. How do it do it with a checkbox?

    This is what i have:

    Code:
    <input type=checkbox name=english value=English>
    I need to add this to it somehow.

    <?=$a112?>
  16. #9
  17. No Profile Picture
    I AM A GOLDEN GOD
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Apr 2003
    Location
    Camarillo, California
    Posts
    5,929
    Rep Power
    1170
    Originally Posted by toolman
    I have another problem now.. How do it do it with a checkbox?

    This is what i have:

    Code:
    <input type=checkbox name=english value=English>
    I need to add this to it somehow.

    <?=$a112?>
    Same methodology as before, only this time you want to add 'CHECKED' to create the currently selected checkbox as per the value in $a112.
    "Seriously, we're not a search engine, we're actual people." ~ ManiacDan

    BookMooch.com : Give books away. Get books you want.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    I'm not quite sure what you mean. So it would be something like:

    PHP Code:
         <select name="lang"> 
    <?php 
    $lang_options
    = array('English','French','German','Spanish''Japanese'); 
    foreach ( 
    $lang_options AS $cbvalue 

        
    // start the option element, insert the current value 
        
    echo "<input type='checkbox' value='{$cbvalue}' "

        
    // ternary operator logic determines which element is selected 
        
    echo ( !empty($a13) && $cbvalue == $a13 ) ? 'SELECTED' ''

        
    // close the option element, display the value to the enduser 
        
    echo ">{$cbvalue}</option>\n"

    ?> 
    </select>
  20. #11
  21. No Profile Picture
    I AM A GOLDEN GOD
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Apr 2003
    Location
    Camarillo, California
    Posts
    5,929
    Rep Power
    1170
    Almost...try
    PHP Code:
    <?php 
    $lang_options
    = array('English','French','German','Spanish''Japanese'); 
    foreach ( 
    $lang_options AS $cbvalue 

        
    // start the input element, insert the current value 
        
    echo "<input type='checkbox' name='lang' value='{$cbvalue}' "

        
    // ternary operator logic determines which element is selected 
        
    echo ( !empty($a112) && $cbvalue == $a112) ? 'CHECKED' ''

        
    // close the input element, display the value to the enduser 
        
    echo ">{$cbvalue}\n"

    ?>
    "Seriously, we're not a search engine, we're actual people." ~ ManiacDan

    BookMooch.com : Give books away. Get books you want.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Posts
    996
    Rep Power
    15
    Thanks, I can't seem to get it to work. Is there not a way i can just use one line like

    PHP Code:
    <input type=checkbox name=english value=English
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Kurvi
    Posts
    490
    Rep Power
    189
    Originally Posted by toolman
    Thanks, I can't seem to get it to work. Is there not a way i can just use one line like

    PHP Code:
    <input type=checkbox name=english value=English
    PHP Code:
    <input type="checkbox" name="enlglish" value="English" <?= if($yourValue == "English" "checked" ""); ?>>

    Comments on this post

    • chadsmith729 agrees : Drive By Rep! {BLAP!} You've been hit!
    Gabba Gabba Hey

IMN logo majestic logo threadwatch logo seochat tools logo