mercredi 4 mars 2015

JSoup parsing form with checkboxes and select input

I have a form which I have to read with jsoup, it contains several fields including checkboxes and comboboxes (select inputs).


I am reading there values with following code -



Element campaignForm = doc.getElementById("Campaign");
Elements allInputFields = campaignForm.getElementsByTag("input");
Elements allSelections = campaignForm.getElementsByTag("select");
Map<String, String> postData = new HashMap<String, String>();
for(Element selectField:allSelections){
postData.put(selectField.attr("name"), selectField.attr("value"));
}

for(Element inputField:allInputFields){
postData.put(inputField.attr("name"), inputField.attr("value"));
}


So when I print the postData Map, it gives correct values for text input fields but for checkboxes and dropdown(comboboxes) it is not working. Please let me know if there is different way to handle checkboxes and select inputs in jsoup.


EDIT: For checkboxes it gives 1 for all the checkboxes whether its checked or not. And for select inputs it gives blank value.


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire