Newbie Question

R

Robert Hogan

Hello,

These are probably a silly questions but I can't get my head around
what is going wrong with this...


I have a asp page, which is primarily written in VBScript (I come from
a VB background so for the moment it's easier to do most of it in
vbscript, I will use JScript when I have some spare time to learn more
about it).

However I'm using bits of Java script in the code to achieve certains
things Eg,

onchange="javascript:document.forms[1].submit();"

which works fine. However I want to set a hidden input value on the
click of the button so I tried using

<form name="GlossaryForm" action="glossary.asp" method="put">

<input type="button"
onclick="javascript:document.GlossaryForm.GetResults.value=True;document.forms[1].submit()"
value="Get Results!">

<input type="hidden" name="GetResults" value="false">
</form>

THere is some vbscript at the beginning of the page that gets the
hidden value and redirects the page accordingly. The problem is that
the button click produces an error and doesn't set the hidden value.

The other weird thing that I noticed while I was trying various things
was that when I did the following,

<html>

<SCRIPT LANGUAGE="Javascript">
vartest = "Hello"
Response.Write("HEllo")
</SCRIPT>

<%
response.write vartest & " World"
%>
</html>

All I get is the " World", Does this mean that you can't pass
variables between JScript and VBScript at all? I guess this makes
sense but why doesn't the response.write in the JScript section
produce any result?

Hope this muddled mess of a post makes sense, I've been staring at
this screen to long trying to get this to work - Please help!

Thanks in advance,

Bob.
 
R

Robert Hogan

onchange="javascript:document.forms[1].submit();"

I assume what you're saying via the insert of that link is that this
use of Javascript isn't a good coding practise due to potential
problems with browsers that don't support javascript?

I actually copied this bit of script from another page of the website
that I'm editing (written by a previous programmer), so the website is
probably full of these javascript references, no ones reported any
problems with this website for the year and a half it's been up - but
I appreciate that it would be good coding practise to make it
compatible across the widest range of browsers possible.
What would the *correct* way of doing this (getting the form to submit
that is on the onchange event) be? I attempted to find this in
vbscript out but couldn't find anything useful, the online support for
vbscript seems to be pretty sparse compared to javascript.

which works fine. However I want to set a hidden input value on the
click of the button so I tried using

<form name="GlossaryForm" action="glossary.asp" method="put">

<input type="button"
onclick="javascript:document.GlossaryForm.GetResults.value=True;document
.forms[1].submit()"
value="Get Results!">

<input type="hidden" name="GetResults" value="false">
</form>

No, it means that you need to get your head around how server-side and
client-side scripts are logically separated.

I think I see, so anything in the <script></script> section is client
side script. I think I can solve the problem using a client side
vbscript function, (I assume that will work for all browsers?), and
avoid javascript until I have a chance to learn it more thoroughly.

Thanks for your help.

Bob.
 
M

Michael Winter

onchange="javascript:document.forms[1].submit();"

http://jibbering.com/faq/#FAQ4_24

I assume what you're saying via the insert of that link is that thisuse
of Javascript isn't a good coding practise due to potentialproblems with
browsers that don't support javascript?

Correct. There's also usually an issue of accessibility.
I actually copied this bit of script from another page of the website
that I'm editing (written by a previous programmer), so the website is
probably full of these javascript references, no ones reported any
problems with this website for the year and a half it's been up - butI
appreciate that it would be good coding practise to make itcompatible
across the widest range of browsers possible.

Users tend not to be so concerned as to raise problems when unable to
access websites. They simply leave and never come back. I'm not saying
that large numbers of visitors have been unable to use the site, but there
have probably been some, and if you're a business, surely that's
unacceptable?
What would the *correct* way of doing this (getting the form tosubmit
that is on the onchange event) be?

Submitting onchange is in itself a bad idea. If a user makes a mistake,
there might not be any time to correct it.

The most common control that receives this treatment is the SELECT
element, and there are a couple of problems with it:

1) It's not unreasonable that the user will simply click the wrong option.
This might be because their choice changes, or it could be a simple
accident.
2) The user attempts to use their mouse wheel to scroll through the
options. Every time the option changes, an event is fired.
3) The user attempts to use the keyboard to scroll through the options,
with similar effects.

The usability guideline that is important here is: don't change the
meaning of the interface. Users don't usually expect an action to be
performed when they select from a list, and why should they? It's not what
the control was designed to do. Buttons perform actions.

[snip]
which works fine. However I want to set a hidden input value on the
click of the button so I tried using

<form name="GlossaryForm" action="glossary.asp" method="put">

<input type="button"
onclick="javascript:document.GlossaryForm.GetResults.value=True;
document.forms[1].submit()" value="Get Results!">

<input type="hidden" name="GetResults" value="false">
</form>

If you are unconditionally setting the value (i.e. just submitting in
itself sets the value), then you could just use a named submit button. The
value of the button will be sent and you could test for that. If you're
not worried about supporting old browsers (like NN4), you could use the
BUTTON element, meaning you don't have to change your server-side code.

<button type="submit" name="GetResults"
value="true">Get Results!</button>

When activated, the button will send the name/value pair, GetResults=true

If you do want to support old browsers (you have been visited by them in
the past), you can do the same with an INPUT element, but the string
you'll check for will be different; "Get Results!", in this case.
I think I see, so anything in the <script></script> section is client
side script.
Yes.

I think I can solve the problem using a client sidevbscript function, (I
assume that will work for all browsers?),

No. VBScript is Microsoft territory and few other browsers - none of the
popular ones[1] - support it.
and avoid javascript until I have a chance to learn it morethoroughly.

If you're going to use any client-side script, it should be JavaScript. If
a browser supports scripting, they are likely to have started with
JavaScript. What you use on the server is entirely up to you.

If you have any problems, there will be plenty of people here that can
help you.

Good luck,
Mike


[1] That statement might not be entirely correct, but I know of no other
browser that supports VBScript.
 
R

Robert Hogan

The usability guideline that is important here is: don't change the
meaning of the interface. Users don't usually expect an action to be
performed when they select from a list, and why should they? It's not what
the control was designed to do. Buttons perform actions.

What I'm doing is dynamically updating a second select list on the
same form. The first list is the category, the 2nd the subcategory. We
want to only show subcategories that relate to the category selected
by the user. The only way of doing this that I've seen is by using the
onchange of the first list to change the content of the 2nd list. Is
there another way to do this?


Thanks for the rest of your suggestions, I'll give them a try now.

Thanks,

Bob.
 
M

Michael Winter

[snip]
What I'm doing is dynamically updating a second select list on thesame
form. The first list is the category, the 2nd the subcategory.We want to
only show subcategories that relate to the categoryselected by the user.
The only way of doing this that I've seen isby using the onchange of the
first list to change the content ofthe 2nd list. Is there another way to
do this?

That's somewhat acceptable. The main abuse of SELECT elements is using
them to navigate through a site. That action, especially if it involves a
form submission, cannot be revoked - the back button doesn't stop the
action from happening - so it is unwise.

If you do use this approach, you should make sure that the page doesn't
break when JavaScript is disabled (unless you can guarantee that none of
your visitors disable JavaScript). If you have server-side support, use
it. It might also be worth your while to look at Richard Cornford's
cascading list implementation:
<URL:http://www.litotes.demon.co.uk/example_scripts/dependent_select.html>

Mike
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top