Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OnChange event extracting value from Select incorrectly

0 views
Skip to first unread message

Robert Carlson

unread,
Sep 14, 2004, 4:55:19 PM9/14/04
to
I am trying to extract the value from a selected item in a
Select/Option, parse it server side using asp and then populate a text
box on the same page with the value that was parsed. simple example
below:

Two problems I have here:

1. The code: this.frmEditUser.Submit; does not appear to submit the
form.
2. If I submit the form using the Submit button, it works except I
get:
"ROBERT" instead of "ROBERT CARLSON - 7788"

<%
Dim sUserId
sUserId = Request.Form("cmbName")
''' Parse: "7788" from "ROBERT CARLSON - 7788"
%>

<html>
<head>
<title>Test Page</title>
</head>

<script language="javaScript">
function GetUserId()
{
alert("GetUserId called");
this.frmEditUser.Submit;
}
</script>

// This page is duly named: "droplistevent.asp"

<BODY>
<form name=frmEditUser action="droplistevent.asp" method="post">
<select size="1" name="cmbName" tabindex="7"
OnChange="GetUserId()">
<option selected>Choose A Name</option>
<option value=ROBERT CARLSON - 7788 > ROBERT CARLSON - 7788
</option>
</select>
<input type="text" name="txtNewId" size="14" tabindex="2"
value=<%=sUserId%>>
<input type="submit" value="Get User Id" name="cmdGetId"
tabindex="8">
</from>
</body>
</html>

Thanks for any support;
Robert

Grant Wagner

unread,
Sep 14, 2004, 5:22:37 PM9/14/04
to
Robert Carlson wrote:

> I am trying to extract the value from a selected item in a
> Select/Option, parse it server side using asp and then populate a text
> box on the same page with the value that was parsed. simple example
> below:
>
> Two problems I have here:
>
> 1. The code: this.frmEditUser.Submit; does not appear to submit the
> form.

The name of the client-side method is "submit()", not "Submit()".

>
> 2. If I submit the form using the Submit button, it works except I
> get:
> "ROBERT" instead of "ROBERT CARLSON - 7788"
>

> <option value=ROBERT CARLSON - 7788 > ROBERT CARLSON - 7788

Quote your value attributes:

<option value="ROBERT CARLSON - 7788">ROBERT CARLSON - 7788</option>

> <input type="text" name="txtNewId" size="14" tabindex="2"
> value=<%=sUserId%>>

Same here:

<input type="text" name="txtNewId" size="14" tabindex="2"
value="<%=sUserId%>">


BE AWARE of possible line breaks or double-quotation marks in your
server-side values. They need to either be escaped or removed/modified.

--
Grant Wagner <gwa...@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Richard Cornford

unread,
Sep 14, 2004, 5:42:18 PM9/14/04
to
Robert Carlson wrote:
<snip>

> Two problems I have here:
>
> 1. The code: this.frmEditUser.Submit; does not appear
> to submit the form.

No it wouldn't. it is a MemberExpression and you want a CallExpression:-

this.frmEditUser.Submit();

However, in the context of the - GetUserId - the - this - keyword is a
reference to the global object and the form is not necessarily going to
be available as a named member of the global object. Access through
the - document.forms - collection is more cross-browser, and passing a
reference to the form from the event handler would probably be easiest
to write and maintain (as the form object becomes anonymous within the
function.


> 2. If I submit the form using the Submit button, it
> works except I get:
> "ROBERT" instead of "ROBERT CARLSON - 7788"

<snip>


> <option value=ROBERT CARLSON - 7788 > ROBERT CARLSON - 7788

The value attribute in the HTML is not surrounded with quote marks and
as a result the parser is likely to regard the first space character
encountered as ending the attribute's string and the following words,
punctuation and number as either authoring errors or custom attributes.
Authoring valid HTML (even with server side scripts) is an effective and
objectively verifiable way of avoiding many scripting errors and can be
recommended for that reason alone.

Richard.


0 new messages