first thanks for you help and support!

My question is how can i correctly make a correct output of html code with variables into. I´m working with jquery and jquery.mobile.

I´m getting from a php results of an database seperated with "," and splitted to an javascript array (works) but I´m not able to output these results correctly to an dynamically working list... they have to be in a list with links and jquery look... but it just show me a list with images without the link and without jquery also it don´t stop to load. My internet research don´t gave me the help I need and I don´t know how to solve this. (Because I want to use PhoneGap, I can´t use php in this part)

Here is my code fragment (just the important things):

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet"  href="css/jquery.mobile-1.2.0.css" />

    <script src="js/jquery.js"></script>

    <script src="js/jquery.mobile-1.2.0.js"></script>


</head>
<body>

                <div id="result">
            <script>
$(document).ready(function(){
    $.post("Test.php",
    {
      q:"Value2ask",
    },
    function(data){

var share=data.split(",");

            if (share.length>=1){
            for(var i = 0; i < share.length; i++)
             {

            var dynlist = dynlist + ('<li><form id="'+share[i]+'" method="POST" action="Next.php" data-ajax="false">'+
            '<input id="id" name="id" value="'+share[i]+'" type="hidden"/> </form>'+
            '<img src="images/pic.png" class="img'+share[i]+'" align="LEFT" width="38" height="38" />'+
            '<a onclick="document.getElementById('+share[i]+').submit();" data-transition="slide" data-ajax="false">&nbsp; '+share[i]+'</a></li>');


            } 
            return document.innerHTML(dynlist);
            } else { 
            var dynlist =   ('<li> <a data-rel="back" data-role="button" data-icon="back" data-ajax="false">No results, click to get back </a></li>');
            return document.innerHTML(dynlist);
            }


    });
});  
</script></div></body></html>

I also tried it with document.write (same result like innerHTML) and some other versions like document.write with every single line .... No positive results ... please help :) Thanks!

share|improve this question
are you getting any errors ? – EnterJQ 17 hours ago
@EnterJQ no the web-developer console stops at the post command ... – MexXxo 17 hours ago

1 Answer

You have var dynlist in for loop of success response.

correct that with

var dynlist;

for(conditions)
{
    dynlist += "code";
}

and instead of returning return document.innerHTML(dynlist); you can use .html(),.text() or .attr() or .append() jQuery methods to add your dynlist to html DOM.

Example

$(documet).append(dynlist);
$('div#result').append(dynlist);
share|improve this answer

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.