How to upgrade select option code
I have some jquery code that is quite old that uses "removeOption(/./).addOption(cats_reg, false)" to change the select options based on a checkbox. The version of jquery is jquery-1.3.2.js.
I have to move my code to where jquery 1.10.2 is being used. The code removeOption(/./).addOption(cats_reg, false) is no longer functions in the new jquery.
- $("#offcampus_ws_box").click(function(){
- $(".offcampws").toggle();
- $(".chngtxt").toggle();
- if (cats_reg !== undefined) {
- if (!($("[name=jobs_workstudy]").attr("checked"))) {
- $("[name=jobs_categories_name]").removeOption(/./).addOption(cats_reg, false);
- if (!wasWorkstudy){
- document.form.jobs_categories_name.selectedIndex=selected;
- }
- } else {
- $("[name=jobs_categories_name]").removeOption(/./).addOption(cats_ws, false);
- $("#benefits_text").html("<strong>Educational Benefits:</strong>");
- if (wasWorkstudy){
- document.form.jobs_categories_name.selectedIndex=selected;
- }
- }
- }
- });
If it helps, cats_reg and cats_ws select option items are created as follows in php:
- $cats_reg = "SELECT categories_name FROM ...";
- $r = pg_query($conn, $cats_reg) or die(pg_last_error());
- echo "var cats_reg = {\n";
- $num = pg_num_rows($r);
- for ($i=0; $i<$num; $i++) {
- $d = pg_fetch_row($r,$i);
- echo "\"$d[0]\"" . " : " . "\"$d[0]\"";
- if ($i<($num-1)){
- echo",\n";
- }else{
- echo"\n";
- }
- }
- echo "};\n";
- $cats_ws = "SELECT categories_name FROM ...";
- $r = pg_query($conn, $cats_ws) or die(pg_last_error());
- echo "var cats_ws = {\n";
- $num = pg_num_rows($r);
- for ($i=0; $i<$num; $i++) {
- $d = pg_fetch_row($r,$i);
- echo "\"$d[0]\"" . " : " . "\"$d[0]\"";
- if ($i<($num-1)){
- echo",\n";
- }else{
- echo"\n";
- }
- }
- echo "};\n";
- }
What is the equivalent or how do I upgrade the code to have it work in the new jquery?
Thanks