开发者

getting value of second input located inside the form. javascript jquery

I have this html form

echo "<form name='delete_article_form".$row['id']."' action='sources/public/article_processor.php' method='POST' >";
echo "<input name='processor_switcher' id='processor_switcher' type='hidden' value='delete_article'><input name='article_id' id='article_id' type='hidden' value='".$row['id']."'><a class='delete_button' href='#'>".$s_delete[$lid]."</a>";
echo "</form>";

Now here is jquery code

$(开发者_运维百科'.delete_button').live('click',function(){
article_id = ???????
        alert(article_id);
    });

What should I do to get the value from input named "article_id"? Problem is that I have several such forms on my page so I must use THIS statement. input=$('input',this).val(); will not help cause there are 2 inputs.

Any Ideas?


Try

var article_id = $(this).closest('form').find('input[name="article_id"]').val();

If you want the 'second' input, then you can do this

var article_id = $(this).closest('form').find('input').eq(1).val();


Use eq(1) to get the second element from the matched set of elements.

article_id = $('input:eq(1)',$(this).closest('form')).val();

Since you have an id to the input fields you can also use. The ids of elements on the page should be unique.

input = $("#article_id").val();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜