Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
178 views
in Technique[技术] by (71.8m points)

javascript - how to pass contents of an html table as form data on a POST?

I have a list of groups in a <select> and a <input type="button" value="Add Selected"> to add the selected group to a <table> of values.

The list of groups that's been added is displayed in a <table>, rows are dynamically added by javascript on each click of the "Add Selected" button. Each row in the table has a "remove" link that removes the item from the table.

Everything works fine, except now I want to POST the contents of the table to a URL, and I'm not sure how to do this.

Should I add an hidden field for each row in the table? Or is there a better way to do this?

Any suggestions are greatly appreciated!

Rob

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Wrap your table in a form and put the data you want to post but not display to the user in hidden inputs

<form method="post" action="">
    <!-- your table -->
    <input type="hidden" name="name" value="your value"/>
    <button type="submit">Post</button>
</form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...