tags:

views:

38

answers:

1

Jquery Code:

$(function() {
$("#submit").click(function(){

var pilaMan = 2;

for (i=0; i < pilaMan; i++)
    {

    $('#dialog_link').dialog({
                modal: false,
                autoOpen: false,
                width: 800,
                height: 300,
                buttons: {
                    "Ok": function() { 
                        $(this).dialog("close"); 
                    }, 
                    "Cancel": function() { 
                        $(this).dialog("close"); 
                    } 
                }
            });

    $('#dialog' + i).click(function(){
                $('#dialog_link' ).dialog('open');
                var lineCode = $('#lineCode').currentElem.prev().val();

                alert(lineCode);

                return false;

            });


    }

});

My Problem with my jquery Code i cant get the exact value of $amew.. and also when i alert the lineCode it will return undefined :(

php code:

$amew = "loso nimo";
$count = 0;
$array = explode(" ", $amew) 

foreach ($array as $value) {

    echo '<td width="68" class="rep" id="dialog'.$count.'">';
    echo '<input type="text" id="lineCode" value="'.$value.'">';

    echo '</td';


}

my problem with my php code is so redundant my jquery codes i solving this for 10 hours and still i cant get it need help guys:(

A: 

Not entirely sure what's being asked -- a few things I noticed is that if you have an ID in a loop (like "lineCode"), there is no way for jQuery to know which one to grab. Also, it looks like you have a single quote in your id tag:

id="lineCode'"

instead of

id="lineCode"


Revised:

PHP Code:

$amew = "loso nimo";
$count = 0;
$array = explode(" ", $amew) 

foreach ($array as $value) {
    echo '<td width="68" class="rep" id="dialog'.$count.'">';
    echo '<input type="text" id="lineCode' . $count . '" value="'.$value.'">';

    echo '</td>';

    $count++;
}

jQuery Code:

$("#submit").click(function(){
    var pilaMan = 2;

    $('#dialog_link').dialog({
        modal: false,
        autoOpen: false,
        width: 800,
        height: 300,
        buttons: {
            "Ok": function() { 
                $(this).dialog("close"); 
            }, 
            "Cancel": function() { 
                $(this).dialog("close"); 
            } 
        }
    });

    for( i = 0; i < pilaMan; i++) {
        $('#dialog' + i).click( function(){
            $('#dialog_link' ).dialog('open');
            alert( $('#lineCode' + i).val() );

            return false;
        });
    }
});
Kerry
sorry.. ^^ i have two loops (loso and nimo) my problem is how can i get each value when i click dialog0 it will return loso and when i click dialog1 it will return nimo.. tnx
mapet
just to simplify things for some, you can use `echo "text".$count++."moretext";`
Adam Kiss