473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OnChange event extracting value from Select incorrectly

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
Jul 23 '05 #1
2 2016
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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
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.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
3
by: Lee Mundie | last post by:
Hi there, Simple problem here but can't seem to fix it! Okay, I have a select list from which people choose avatars... the list is option values ie. <option>Worm</option> ...
10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.