0

Hy,

I have the following situation. I have a form where I read from database values and put them in an select like this

HTML code :

<select id="model" name="model">
    <option value="0">choose...</option>
</select>

Javascript code :

var nrcrt = $("input#type option:selected").attr('value');
    $.post("select_model.php", {nrcrt:nrcrt}, function(data){
    $("select#model").removeAttr("disabled");
    $("select#model").html(data);
});

in nrcrt I have a value from a previous select which I use in select_model.php to make the query to mysql.

The question is: can anyone help me transform this from a select to a checkbox list?

Thank you.

3
  • 1
    Would you then want to send multiple values if more than one checkbox was checked? Commented Apr 23, 2013 at 13:20
  • Please show us what you've tried so far. Commented Apr 23, 2013 at 13:28
  • As I answered to codefreak, yes I want to send the values back to the db and to be able to select multiple values. The system is working with the current option drop down, but is very time consuming when I have to select from a list of 100 values 40 of them and update the db witj each one selected. Commented Apr 24, 2013 at 7:13

1 Answer 1

1

Haven't tested it, but this might do what you want:

var html = "";
    $("#model>option").each(function(){
     html+="<input type='checkbox' name='model[]' value='" + $(this).attr("value") + "'/>" + $(this).text() + "<br/>";
    });
    $("#model").after(html);
    $("#model").remove();
Sign up to request clarification or add additional context in comments.

3 Comments

What I understand you want to do is actually create radio's for every value. The thing is I want to be able to select multiple values and after that send them to another table in the db. So this is not very helpfull but thanks anyway for the answer.
check modified code, now you can use check boxes instead of radio, when data is submitted $_POST[model] will be an array containing all checked values
Yeeeee! It did the trick with a little tweaking and use of my own variables but in the end the result is perfect. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.