Php list of forms

I have the following piece of code, inside a php script

foreach( $results as $i => $value ){ ?>
    <li><form action="getDetail.php" id="detailForm<?= $i ?>" >
    <input name="application" value="myTemplate" type="hidden" />
    <input name="user" value=<?= $value->publisherID ?> type="hidden" />
    <a href="javascript:document.getElementById('detailForm<?= $i ?>').submit();" >
    <div class="row" style="padding-left: 10px;"><?= $value->publisherName ?></div>
    </a></form></li>
<?php }

it's working, but I was wondering how I could put this better

remove all form id's and put something more generic like

<a href="javascript:$(this).parents('form').submit();" >

which is not working

neither does:

<a href="javascript:$('#detailForm<?= $i ?>').submit();" >

(gives this jquery error-> Uncaught Error: Syntax error, unrecognized expression: );'))

thanks

Answers


i think maybe the parents() function returns a list, try doing like this instead:

<a href="javascript://" onclick="$(this).closest("form").submit(); return false">

At the end of the for each loop i would do $i++ so that your id's are unique

If you wan to have a semanticaly correct webpage you need to have id's to your input.

Regarding rewriting your code if you want jquery to handle your code for example with json you can do something with the following code

$(document).ready(function() {
    $('.preloader<?php echo $i; ?>').html('<img src="ajax-loader.gif" />'); 
    $.post('post.php', $("#detailForm<?php echo $i; ?>").serialize(),
        function(data){
            $('#returnData<?php echo $i; ?>').html(data.returnData);
            console.log(data);
        },'json');


});

Hope it helps, and if i'm thinking in the same way as you do.


Need Your Help

google chrome like close button behavior in css

html css google-chrome button

How would you replicate the behavior of tabs in google chrome with css?

EmberJS - classNameBindings w/ Observe & Property Not Updating/Firing

ember.js

This is a really basic question and I've been trying to figure it out to no avail. I'm integrating Google Maps with EmberJS and trying to do classNameBindings on a property within the IndexController

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.