diff --git a/src/ecmascript/see/form.c b/src/ecmascript/see/form.c index 358ec2b6b..ec7cbbb8f 100644 --- a/src/ecmascript/see/form.c +++ b/src/ecmascript/see/form.c @@ -331,6 +331,16 @@ input_put(struct SEE_interpreter *interp, struct SEE_object *o, mem_free_set(&fs->value, string); if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fs->state = strlen(fs->value); + } else if (p == s_selectedIndex) { + if (fc->type == FC_SELECT) { + SEE_uint32_t item = SEE_ToUint32(interp, val); + + if (item >=0 && item < fc->nvalues) { + fs->state = item; + mem_free_set(&fs->value, stracpy(fc->values[item])); + fixup_select_state(fc, fs); + } + } } } diff --git a/src/ecmascript/spidermonkey/form.c b/src/ecmascript/spidermonkey/form.c index 55eb1b632..caae91d0c 100644 --- a/src/ecmascript/spidermonkey/form.c +++ b/src/ecmascript/spidermonkey/form.c @@ -300,6 +300,17 @@ input_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp) if (fc->type == FC_TEXT || fc->type == FC_PASSWORD) fs->state = strlen(fs->value); break; + case JSP_INPUT_SELECTED_INDEX: + if (fc->type == FC_SELECT) { + int item = atoi(jsval_to_string(ctx, vp)); + + if (item >= 0 && item < fc->nvalues) { + fs->state = item; + mem_free_set(&fs->value, stracpy(fc->values[item])); + fixup_select_state(fc, fs); + } + } + break; default: INTERNAL("Invalid ID %d in input_set_property().", JSVAL_TO_INT(id)); diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c index 90b809f13..cb9134402 100644 --- a/src/viewer/text/form.c +++ b/src/viewer/text/form.c @@ -89,7 +89,7 @@ done_submitted_value(struct submitted_value *sv) mem_free(sv); } -static void +void fixup_select_state(struct form_control *fc, struct form_state *fs) { int i; diff --git a/src/viewer/text/form.h b/src/viewer/text/form.h index 1bf47982a..aebc19b87 100644 --- a/src/viewer/text/form.h +++ b/src/viewer/text/form.h @@ -72,6 +72,7 @@ struct uri *get_form_uri(struct session *ses, struct document_view *doc_view, st unsigned char *get_form_info(struct session *ses, struct document_view *doc_view); +void fixup_select_state(struct form_control *fc, struct form_state *fs); void selected_item(struct terminal *term, void *item_, void *ses_); int get_current_state(struct session *ses);