Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an OpenLayers pop-up with a form on selectFeature (WFS-T). Can I recover the feature.attributes in the form's onSubmit?

e.g: the form in the popup

var content = '<form onSubmit="processForm(this.form)">' +
    'Träd-Id<br><input type="text" name="trädnummer" value="' +
    feature.attributes.trädnummer + '">' +
    '<br>Art<br><input type="text" name="art" value="' + + '">' +
    '<br>Anmärk.<br><textarea name="anmärkningar" rows="4" cols="40">' +
    feature.attributes.anmärkningar + '"</textarea>' +
    '<br>Åtgärd<br><textarea name="anmärkningar" rows="4" cols="40">' +
    feature.attributes.rekommendationer + '"</textarea>' +
    '<br><input type="submit" value="Spara""></form>'

and the onSubmit callback:

function processForm(oForm) {
  var feature = **recover currently selected feature here?**
  feature.attributes.trädnummer = 
    oForm.elements["trädnummer"],value; = 
  feature.attributes.anmärkningar = 
  feature.attributes.rekommendationer = 
  return false;

If so, I thought I could use WFS-T to update the attribute info? (instead of e.g. a post to php) Any help appreciated
Thanks Mini

share|improve this question
up vote 1 down vote accepted

Just a thought: you can add a hidden field in the form with id of your feature and then reach the feature itself (so attributes too) by this id (via getElementById) in onSubmit callback.

share|improve this answer
Thanks @unibasil - that's sorted it. I also got rid of the <form> and onSubmit stuff and used the WFS-T I'd already set up (feature.state = OpenLayers.State.UPDATE;; in a button click handler). I'll post the updated code. – minisaurus Mar 26 '13 at 7:54
Forgot to mention, I added ids based in in the input fields and used getElementById to recover the inputs in the button click handler. I used this.wfs.selectedFeatures[0] to get to the attributes in the button click handler – minisaurus Mar 26 '13 at 7:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.