简体   繁体   中英

Dynamically added input box problem?

I have dynamically added div.In which i have text box.While adding dynamic div i can put a value to the current div but not the previously open divs. I want to ask how to add Value to the previously open text boxes of Div.

Thank You

here is a solution that refresh ALL . (I don't understand the "previously open text box" part of your question. Well I understand it, but it doesn't show in your code. I assume the "rhythm" column of your table is an input/textarea html element (since you use it's value).

Please note I'm not sure what the vitalset function is supposed to accomplish, or what "vitals_form_readings_1_rhythm" is.

function queryDb(statement)
{
    dbQuery = new air.SQLStatement();
    dbQuery.sqlConnection = db;
    dbQuery.text = statement //"SELECT * FROM rhythm";
    //alert(dbQuery.text);
    try {
        dbQuery.execute();
        } catch (error) {
        air.trace("Error retrieving notes from DB:", error);
        air.trace(error.message);
    return;
    }
    return (dbQuery.getResult());
}

function crhythm()
{
    var statement = "SELECT * FROM rhythm";
    return queryDb(statement)
}

function reading_speedcode()
{
    if (!cvitals) {
        var crhythms = crhythm();
        var i=0;
        $(crhythms).each( function () {
            crhythm = this.crhythm;
            var pr = 'card_' + i;
            $('#rhythm1').append('<br/><td class="content_big" id="'+pr+'" name="'+pr+'">' + crhythm + ' </td>');
            i++
        });
    }
});

$(document).ready( function () {
    reading_speedcode();

    $('#rhythm1 .content_big').live('click', function(event) {
        $('#rhythm1').empty()
        reading_speedcode();
    });
});

now, there are several things about your code.

  1. variable naming. (for god sake use meaningful names!)
  2. reading full table when you need one row
  3. where is cvitals declared or assigned?
  4. string parsing. Jquery is good at working with set of elements, there should be no need to parse "pr" to recover the row number.
  5. if a value is inserted in rhythm table (or deleted) before your click, the vitalset logic fails. you might want to use the table id instead.
  6. make sure "#vitals_form_readings_1_rhythm" is unique, not retrieved from the table.

if you can answer my question from the top of this post(vitalset function, vitals_form_readings_1_rhythm, cvitals) I will try improve the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM