最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Aug 19, 2011 at 11:43 David asked Aug 19, 2011 at 11:36 DavidDavid 4,50814 gold badges61 silver badges104 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

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)

  1. 暂无评论