SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how can i make this auto selected !?

    hi ..

    Code:
    document.advert.Type.options[document.advert.Type.options.length] = new Option(' Type 2 Zoon 2 ','2');
    how to make this selected when page is loaded ?







    thx

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (Where is the definition of the Option object?)

    Updated: OK, I wasn't thinking...
    The Option() constructor accepts up to four parameters:
    text (string)
    value (string)
    defaultSelected (boolean)
    selected (boolean)
    (JavaScript Bible, Danny Goodman)
    Last edited by jofa; Jun 16, 2002 at 07:46.

  3. #3
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add this line after the other one:
    Code:
    document.advert.Type.options[document.advert.Type.options.length-1].selected = true;

    M@rco

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    M@rco, you beat me to it - you posted while I was updating my response!

    jofa

  5. #5
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol! We're square then!!!


    M@rco

  6. #6
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm .. i`ll try it ..

    this code is for 3 select tag it`s coming coming from Db, for cars code ,look like this :

    Country , Mark , Category ,

    so user must select country, then Mark, then Category, it work as i need when user submit, but when update i need to make auto select !

    i think this to complect




    thx .. i`ll post the result soon !

  7. #7
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry - I don't follow you!
    (Please restate mission!)


    M@rco

  8. #8
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think Richi is talking about how to make the value from the database the selected option

    var optTag = document.advert.Type.options[document.advert.Type.options.length-1];
    optTag.selected = (optTag.value == dbValue);

    Correct?

    BTW, do you use hungarian notation in Budapest?
    J jt (or is it J reggelt?)
    Last edited by jofa; Jun 16, 2002 at 20:35.

  9. #9
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didn`t work
    the main select is the country, u must select the country to view the Marks, i do it auto select for the country, but i must change it to get the Marks list

    it seems will not work !


    here is part of the code :
    [php]
    // the country select
    Function Car_Select1($Form_Name,$Type,$Sel){

    $q = @mysql_query("select * from car_zoon ");


    $car_menu = "<select name=\"Zoon\" onchange=\"gettype(this)\" Class=input1>\n\n";
    if($Type == "post"){
    $car_menu .= "<option value=\"\" > </option>\n\n";
    }else {
    $car_menu .= "<option value=\"AllZoon\" >Country</option>\n\n";
    }


    while($r=@mysql_fetch_array($q)){
    extract($r);
    ($Sel == $zoon)? $Selc = "selected" : $Selc = "";
    $car_menu .= "<option value=\"$zid\" $Selc>&nbsp; $zoon </option>\n\n";
    }
    $car_menu .= "</select>";
    return $car_menu;
    }



    // The mark select ..


    Function Car_Select2($Form_Name,$Type,$Sel) {

    $car_menu .= "<select name=\"Type\" onchange=\"getmodel(this)\" Class=input1>\n\n ";
    if($Type == "post"){
    $car_menu .= "<option value=\"\"> Mark</option>\n\n";
    }else{
    $car_menu .= "<option value=\"AllType\"> All </option>\n\n";
    }


    $car_menu .= " <SCRIPT language=JavaScript>
    function gettype(elem){
    for (var i = document.$Form_Name.Type.options.length; i >= 0; i--){
    document.$Form_Name.Type.options[i] = null;
    }\n\n ";

    $car_menu .= "if (elem.options[elem.selectedIndex].value=='AllZoon'){ \n\n";
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length] = new Option(' All ','AllType');\n}\n";

    $car_menu .= "if (elem.options[elem.selectedIndex].value==''){ \n\n";
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length] = new Option(' Mark ','');\n}\n";

    $q2 = @mysql_query("select * from car_zoon");

    while($r2= @mysql_fetch_array($q2)){

    $car_menu .= "if (elem.options[elem.selectedIndex].value=='$r2[zid]'){ \n";
    $q3 = @mysql_query("select * from car_type where zid='$r2[zid]' ") ;
    if($Type != "post"){
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length] = new Option(' All ','AllType');\n";
    }else {
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length] = new Option('Mark ','');\n";
    }
    while($r3=@mysql_fetch_array($q3)){
    ($Sel == $r3[type]) ? $x = "-1" : $x = "";
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length$x] = new Option(' $r3[type] ','$r3[car_id]');\n";
    }
    $car_menu .= "}\n";
    }


    $car_menu .= "}</script>\n\n";
    $car_menu .= "</select>";
    return $car_menu;

    } // End 2

    [php]

    when i view the html source i found -1 on the right select, but on view there just Mark , need to select the country 1st !

    grrrr .. i give it up !!


    Jofa :
    hat ahogy latod, hu - bp , akkor nem a marson vagyok

  10. #10
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jofa, I'll leave this one for you!
    PHP ain't my bag, baby!!


    M@rco

  11. #11
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1.
    I think you should move the line (in Car_Select2)
    $car_menu .= "</select>";
    to the line above
    $car_menu .= " <SCRIPT language=JavaScript> ...

    2.
    Can you explain this?
    $Sel == $r3[type]) ? $x = "-1" : $x = "";
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length$x] = new Option(' $r3[type] ','$r3[car_id]');\n";

    3.
    Examples of html output?

    4.
    "hat ahogy latod, hu - bp , akkor nem a marson vagyok"
    As I can see, you are not on Mars, on march, eating a Mars bar in a marsh?

  12. #12
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hali...


    the code is work now as i need

    PHP Code:
    ($Sel == $r3[type]) ? $x "-1" $x ""
    $car_menu .= "document.$Form_Name.Type.options[document.$Form_Name.Type.options.length$x] = new Option(' $r3[type] ','$r3[car_id]');\n"
    in php function i give the type which is selected form db ($Sel) , then if $Sel eq the type from the db will be selected, so i need to put -1 in js code to make it autoselected .


    "hat ahogy latod, hu - bp , akkor nem a marson vagyok"

    as u see, hu- bp , them am not on the Mars


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
  •