form issues

M

middletree

I have an issue that may or may not be appropriate here, as it has to do
with client-side code. Does MS have a better forum than this one for this?
(Microsoft forum would be best. I don't have access to Usenet here at work)

Here's the problem:

Yesterday, I posted a dilemma I am facing, and got an answer, but wasn't
able to try it till today, and it doesn't work. To review:

Select box on the left contains all employees. Select box on right is empty
when the page loads. Arrow button in the middle allows you to select an
employee from the left, and it appears in the right box when the arrow
button is clicked. You can do this more than once. This all works fine.

Of course, I want it to be able to pass the values in the right box on to
the next page when I click the submit button. However, nothing gets passed.
However, when I add a name or two to the right box, and then manually select
the name(s), it does get passed to the next page. But it isn't practical to
ask someone to essentially select the names twice.

When I posted this yesterday on the Macromedia forum, I received advice to
add this code to the submit button:

onclick="selectAllOptions(document.frm.SelectedEmp)"

(where the form name is frm, and the right box is named "SelectedEmp")

Like I said in my first paragraph, it doesn't work. I suspect that it is
related to the fact that in the form tag, I have an onSubmit item, telling
it to go through the Javascript code I have for validation.

Anyone know if this could affect this. let me know. If anyone has helpful
advice, please let me know. I can't believe no one has ever done this
before. I have seen it countless times. I think.
 
D

Dave Anderson

middletree said:
Select box on the left contains all employees. Select box on right
is empty when the page loads. Arrow button in the middle allows you
to select an employee from the left, and it appears in the right
box when the arrow button is clicked. You can do this more than
once. This all works fine.

Of course, I want it to be able to pass the values in the right box
on to the next page when I click the submit button. However, nothing
gets passed. However, when I add a name or two to the right box, and
then manually select the name(s), it does get passed to the next
page. But it isn't practical to ask someone to essentially select
the names twice.

I assume you are using a <SELECT MULTIPLE> on the right, and want to simply
grab every value. Is that correct?

If so, then you have a couple of options. The first is to intercept the form
submission and select every element programmatically. The second is to store
the list in a hidden input, updating every time a name is added/dropped.
This is probably the least troublesome way, IMO.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
A

Andrew J Durstewitz

The only time something won't be sent with the Submit is when you have a
blank value for the pull down.

In this case you need...
Response.Write "<option value=" & strValue & ">" & strLabel &
"</option>" & chr(13)

That is a line writter that I am using inside of an ASP script to write
the lines for the pull down menu.

If your value is empty then nothing will be sent.

hth,
Andrew

* * * Sent via DevBuilder http://www.devbuilder.org * * *
Developer Resources for High End Developers.
 
D

Dave Anderson

Andrew J Durstewitz said:
The only time something won't be sent with the Submit is when
you have a blank value for the pull down.

I can think of a few others. Omit the NAME attribute on the SELECT. Set the
READONLY or DISABLED attributes. Place the object outside the form. Use
<SELECT MULTIPLE> and nothing is selected by the user...


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
T

TomB

I did the following and it seems to work....I'm sure there are better
ways...but...


<%@ Language=VBScript %>
<% OPTION EXPLICIT %>

<HTML>
<HEAD>
<SCRIPT Language=Javascript>
function Move()
{

theForm.theRight.options[theForm.theRight.length]=new
Option(theForm.theLeft.options.value);
theForm.SelectedEmployees.value=theForm.SelectedEmployees.value + ", " +
theForm.theLeft.options.value;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name=theForm id=theForm method=post action=test.asp>
<input type=hidden name=SelectedEmployees value="">
<%
Dim field
for each field in Request.Form
Response.Write "<LI>" & field & ": " & Request.Form(field) & "</LI>"
next
%>

<table>
<tr>
<td valign=top>
<SELECT name=theLeft size=10 >
<OPTION value="JOJO">JoJo</OPTION>
<option value="BOB">BOB</option>
<option value="Fred">Fred</option>
</SELECT>
</td>
<td valign=top>
<input type=button value=">>" onClick="Move();">
</td>
<td valign=top>
<SELECT name=theRight size=10 multiple>
</SELECT>
</td>
</tr>
</table>
<input type=submit value="Submit Query">
</FORM>

</BODY>
</HTML>
 
D

Dave Anderson

middletree said:
The first is to intercept the form submission and
select every element programmatically.

I have no idea how to do this. Got any sample code?

There are two schools of thought on intercepting the form submission. The
first is to depend on scripting to submit the form:

<FORM ONSUBMIT="return false" ...>
<BUTTON ONCLICK="doStuff()" ...>...</BUTTON>
...
function doStuff() {
...
document.myform.submit()
}

The second is to use a validation/maintenance script:

<FORM ONSUBMIT="return validate(this)" ...>
...
function validate(f) {
if (some conditions are met) return true
else return false
}

There's nothing stopping you from adding an extra step to the
validation/maintenance script:

...
var obj = document.myform.mySelectMultiple
for (var i=0; i<obj.length; i++) obj.selected = true
...
Not sure how to update it when names are added or dropped.

In the event handler that adds an element, add another step. Do the same for
the [drop name] handler. Example:

<INPUT TYPE="hidden" NAME="myRealList">
<SELECT MULTIPLE NAME="myDisplayList"></SELECT>
<INPUT TYPE="button" VALUE="Add Name" ONCLICK="Add()">
<INPUT TYPE="button" VALUE="Remove Name" ONCLICK="Remove()">
...
function updateRealList() {
var a = [], obj = document.myform.myDisplayList
for (var i=0; i<obj.length; i++) a.push(obj.value)
document.myform.myRealList.value = a.join()
}
function Add() {
... // this code remains the same as before
updateRealList() // this is all you add
}
function Remove() {
... // this code remains the same as before
updateRealList() // this is all you add
}

Untested, so there may be typos.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
M

middletree

Dave Anderson said:
...
var obj = document.myform.mySelectMultiple
for (var i=0; i<obj.length; i++) obj.selected = true
...



I think the key is in this line here. I have somethign similar, yet it is
not selecting the options like it should.
 
M

middletree

Well, thanks for your help. I got it.

What I did was I took this line out of a function and put it into my
validation script, right above the "return true;"

frm.SelectedEmp.options[intIndex].selected = true


Thanks very much for your help on this.

James W
 
D

Dave Anderson

middletree said:
for (var i=0; i<obj.length; i++) obj.selected = true


I think the key is in this line here. I have somethign similar,
yet it is not selecting the options like it should.


What do you have?


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Range / empty list issues?? 1
Image issues 0
C# MVC Razor page form 0
Grid Stacking Game Issues 5
Login form no longer working 2
Contact form question 2
Registration Form 7
Mailbox form automation 0

Members online

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top