Option group help for a beginner?

W

What-a-Tool

I have a school project (ASP) in which I have to call three different ASP
pages from three different and identical (except for the form "action",
obviously) HTM pages. This I have no problem with.
However, as a personal learning project and challenge, I decided to see if I
could code my initial HTM page to call any of the three ASP pages, depending
on the condition of an option group. (3 buttons - id="function", id="sub",
id="class")
I was hoping it would be as simple as putting a function name in my form
"action" statement. In the function I thought I would use a switch statement
to determine the action from the condition of the option group.
After playing around with this for a couple hours last night, I decided I
had failed miserably, and it was time to look for some knowledgeble advice.

Can someone help? Or direct me to a sample somewhere?

Thank You
--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
K

kaeli

Die!FrigginSpammersDieDie! said:
However, as a personal learning project and challenge, I decided to see if I
could code my initial HTM page to call any of the three ASP pages, depending
on the condition of an option group. (3 buttons - id="function", id="sub",
id="class")
I was hoping it would be as simple as putting a function name in my form
"action" statement. In the function I thought I would use a switch statement
to determine the action from the condition of the option group.
After playing around with this for a couple hours last night, I decided I
had failed miserably, and it was time to look for some knowledgeble advice.

Can someone help? Or direct me to a sample somewhere?

The action for the form should be the URL of a default "no javascript"
page. i.e. action="noscript.html". Or it can be a default page -
whatever you want to have happen if the user has no script or has it
disabled.
The onSubmit of the form should call the function, assuming your button
is a submit button. i.e. type="submit" and onSubmit="return myFunction
()".
The function can then look at the option group and change the
location.href property accordingly. It should then return false so the
form doesn't actually submit (the location change should fire before
that, but better safe than sorry).

Oh, and it's always a good idea not to name things the same name as
other things. Don't name elements "function" or "id" or "class" or
"name" and so on. Most of the time it isn't an issue, but it can be, so
getting in the habit of just not doing it can save you a headache later.
Same goes for naming things with numbers at the beginning, like
name="2btn" or some such. It isn't technically illegal, but it can cause
hassles sometimes.

--
--
~kaeli~
Murphy's Law #2030: If at first you don't succeed, destroy
all evidence that you tried.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
R

Richard Cornford

What-a-Tool wrote:
However, as a personal learning project and challenge, I decided to
see if I could code my initial HTM page to call any of the three ASP
pages,

As a learning exercise fair enough, as a design decision with potential
real world applications exercise extreme caution as without this HTML
forms and server-side ASP are 100% reliable (or at least as close as
possible) but with this the whole system becomes dependent on
client-side squirting, which is a long way from 100% reliable or
universally available on clients.
depending on the condition of an option group. (3 buttons -
id="function", id="sub", id="class")

Do you mean <input type="radio"> buttons? Calling them options is likely
to be misleading to anyone who understands HTML because they are likely
to think of OPTION elements (which are not buttons).
I was hoping it would be as simple as putting a function
name in my form "action" statement.

The action attribute of a form is specifies as containing a URL so it is
of no value in executing scripts (except on a very few browsers where
its use with the javascript: protocol is a seriously misguided dubious
hack, and always unnecessary).
In the function I thought I would use a
switch statement to determine the action from the condition of the
option group.
After playing around with this for a couple hours last night, I
decided I had failed miserably, and it was time to look for some
knowledgeble advice.

Read section 2.3 of the newsgroup FAQ and the pages it links to.

<URL: http://www.jibbering.com/faq/#FAQ2_3 >

The best place to trigger a function that intends to set the - action -
property of a form is from the onsubmit handler, as the onsubmit handler
is called when the form is submitted, but prior to the actual submit (so
it may be cancelled, for example, as a result of failed client-side
validation). If code in the onsubmit handler, or a function called from
there, sets the form's - action - property then the URL assigned will be
used when the form is submitted.

Richard.
 
B

bruce

What-a-Tool said:
I have a school project (ASP) in which I have to call three different ASP
pages from three different and identical (except for the form "action",
obviously) HTM pages. This I have no problem with.
However, as a personal learning project and challenge, I decided to see if I
could code my initial HTM page to call any of the three ASP pages, depending
on the condition of an option group. (3 buttons - id="function", id="sub",
id="class")
I was hoping it would be as simple as putting a function name in my form
"action" statement. In the function I thought I would use a switch statement
to determine the action from the condition of the option group.
After playing around with this for a couple hours last night, I decided I
had failed miserably, and it was time to look for some knowledgeble advice.

Can someone help? Or direct me to a sample somewhere?

Thank You


In the <form> tag, for "action", put
action="Javascript:DoProcess()"
Then you can query your option buttons in DoProcess(), do a
form.submit(), do whatever you want there.

Better yet, I've found that instead of having a submit button, it's
better to just use a plain button, which executes a function which
does form.action,form.method, does editting, and finally a
form.submit.
 
K

kaeli

Better yet, I've found that instead of having a submit button, it's
better to just use a plain button, which executes a function which
does form.action,form.method, does editting, and finally a
form.submit.

Except for internet sites that need to work for users who don't have
javascript. Which all commercial web sites should be able to handle.
My intranet application, however, does this very thing so that users
HAVE to enable script to use it.

--
--
~kaeli~
Have you forgotten about Jesus?
Isn't it about time you did?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 
W

What-a-Tool

Thanks for your help - I got it working.

In my function to determine radio button choice I used frmMyForm.action =
"mypage.asp"

location.href wasn't sending my data entries to the ASP page, whether by my
lack of know how or otherwise. frmMyForm.action = "" did though.

Once again, thanks

--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
W

What-a-Tool

Have just discovered that using this method doesn't work in Netscape(7.1)
for some reason. (setting my form action with < frmMyForm.action =
"myasp_page.asp" > ) This works fine in IE.

Using the location.href to set my page brings me to the proper page, but
doesn't send my form data to the server. (at least not so my asp page can
read it)

Is there another way to do this so it will at least work in Netscape as well
as IE?

--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
W

What-a-Tool

Alright - I give - what is it that I'm doing wrong?
Yeah, I read the faq. Sorry - don't see the relevance.

Did a search for related posts - didn't find one.

If I'm posting in the wrong group, point me in the right direction.

If I'm asking a stupid question, sorry - I stated in the subject that I was
a beginner.

Is it because the question relates to ASP?
Sorry - I thought it dealt more with the client side JavaScript I'm trying
to code.

Please tell, rather than continually pointing at the same overly wordy faq
sheet that I don't have time to read every word of.

--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Richard Cornford
<snip>

Did you read section 2.3 of the newsgroup FAQ and the pages it links to?
If so why have you disregarded what they say?

<URL: http://www.jibbering.com/faq/#FAQ2_3 >

ISTM that Sec 2.3 does need to have its paragraphs numbered (perhaps
with <H4>); and that it might be improved by a total re-write.

No doubt you had Paragraph 6 particularly in mind.


I was thinking about testing javascript and Web pages; sometimes I fear
that novices may edit their sources, upload to the web, and test while
on-line, without realising that it can all be tested locally. Clearly
there's quite a bit that could be said, and the FAQ should not itself
say much; but there should be room for a few links, that could be found
by searching for "test" and "valid". Perhaps a page in the Notes?
 
W

What-a-Tool

..
No doubt you had Paragraph 6 particularly in mind.

AAAHH! - I think I get it - Sorry



--

/ Sean the Mc /


"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
R

Richard Cornford

Dr said:
Richard Cornford wrote:

ISTM that Sec 2.3 does need to have its paragraphs numbered (perhaps
with <H4>); and that it might be improved by a total re-write.

There are quite a lot of similar suggestions for improvements to the
general presentation (in text and HTML versions) but they will take a
serious revision of the XML format used as the current version will not
accommodate them. I did start looking into revising the XML format to
make it more flexible/expressive but I don't want to commit to a new
format until I have got it right, else it will become another ongoing
task.
No doubt you had Paragraph 6 particularly in mind.

Well I didn't know how the OP would be replying to post when I initially
made the suggestion. I was thinking more in terms of the general advice
on asking questions, and particularly the suggestions about posting
code. Though I didn't want to be that specific in case the other
important material was missed along the way.
I was thinking about testing javascript and Web pages; sometimes I
fear that novices may edit their sources, upload to the web, and test
while on-line, without realising that it can all be tested locally.
Clearly there's quite a bit that could be said, and the FAQ should
not itself say much; but there should be room for a few links, that
could be found by searching for "test" and "valid". Perhaps a page
in the Notes?

Testing on a live site isn't a good idea, but uploading to a test area
within a site wouldn't be that inconvenient given a broadband
connection. But a page on testing wouldn't be a bad idea either.

Richard.
 
W

What-a-Tool

Following is some of my code:

<form name="frmsubmitF" id="frmsubmitF" onsubmit="return wheretogo();"
action="../noscript.htm" method="post">

function wheretogo()
{

if (eval("document.frmsubmitF.callfunc.checked") == true)
{
alert("Calling ASP Function");
frmsubmitF.action = "converttempfunction.asp";

----------------------------------------------------------------------------
--

My Problem has been pointed out to me :

Above:
frmsubmitF.action = "converttempfunction.asp";

Should be:
document.frmsubmitF.action = "converttempfunction.asp";


--

/ Sean the Mc /

"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
 
R

Richard Cornford

What-a-Tool wrote:
if (eval("document.frmsubmitF.callfunc.checked") == true)

As you are learning you might like to know that it is never necessary to
compare a boolean value with a boolean value to get a boolean result, as
you are doing in this case. The - checked - property of a checkbox/radio
button is a boolean property, its value is either true or false. The
comparison operator - == - produces a boolean result, true if the
(type-converted) values are equal, false otherwise. When you compare a
boolean value that may be either true of false with true the result you
will get will be true is the value was true and false if the value was
false. Making the comparison an extra operation that always returns a
value equivalent to the value being tested.

The - if - statement examines its expression to see if its
(type-converted to boolean) value is true of false, so merely placing a
reference to the appropriate - checked - property in the - if -
expression will have exactly the same outcome as your comparison
operation.

Also, the - eval - function is almost never needed in javascript, and so
almost never used by javascript authors who know what they are doing. It
is often used to resolve dynamically created dot notation property
accessors, javascript natively offers bracket notation property
accessors for that task so - eval - isn't needed for that task (and is
extremely in efficient at the task). But you are not even evaluation a
dynamically constructed dot notation property accessor. Your string
value for use with - eval - is literal and so:-

eval("document.frmsubmitF.callfunc.checked")

- is *exactly* the same, in terms of what it does, as:-

document.frmsubmitF.callfunc.checked

- except that the - eval - call is two to twenty times slower (depending
on the browser) and may not function on ECMA 327 "compact profile"
implementations (as might be found in small embedded browsers), where -
eval - is optional.

So your - if - statement can be re-written as:-

if(document.frmsubmitF.callfunc.checked){

- and do exactly the same as it does now, but be faster, clearer and
more reliable.

My Problem has been pointed out to me :

Above:
frmsubmitF.action = "converttempfunction.asp";

Should be:
document.frmsubmitF.action = "converttempfunction.asp";

And that is an error that is impossible to guess but easy to *see*.

Incidentally, asking people to write you specific explanations because
you "don't have time to read every word of" a pre-written explanation
that you have been referred to is not going to go down well on Usenet.
These web page explanations get written to save us time by not having to
re-write the same explanation of the same things over and over again.

Richard.
 
W

What-a-Tool

As you are learning you might like to know that it is never necessary to
compare a boolean value with a boolean value to get a boolean result, as
you are doing in this case.
Also, the - eval - function is almost never needed in javascript, and so
almost never used by javascript authors who know what they are doing.
eval("document.frmsubmitF.callfunc.checked")

- is *exactly* the same, in terms of what it does, as:-

document.frmsubmitF.callfunc.checked

- except that the - eval - call is two to twenty times slower
So your - if - statement can be re-written as:-

if(document.frmsubmitF.callfunc.checked){

- and do exactly the same as it does now, but be faster, clearer and
more reliable.

Thanks for the code evaluation.
My background is in VB.Net - the double check for a boolean makes sense - I
wouldn't do it in VB, but don't see these things quite so clearly in
Jscript. Thanks for the pointer and the tip on eval

Incidentally, asking people to write you specific explanations because
you "don't have time to read every word of" a pre-written explanation
that you have been referred to is not going to go down well on Usenet.
These web page explanations get written to save us time by not having to
re-write the same explanation of the same things over and over again.

Richard.

I did skim thru the faq the first time you directed me there. As you can
see, I didn't know which paragraph you you were
refering to. My oversite. Usually, when I resort to a newsgroup post, I am
in the middle of a project, stuck, frustrated, and hoping for a solution as
quick as possible. (and usually get it)
You directed me there a second time - I skimmed thru it again and still
didn't see. Other things on my mind I guess. Again - my mistake.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Richard Cornford
There are quite a lot of similar suggestions for improvements to the
general presentation (in text and HTML versions) but they will take a
serious revision of the XML format used as the current version will not
accommodate them.

Surely the paragraphs can be numbered by inserting <number stop space>
in the source immediately before the first word? There's only about ten
of them. Or <parenthesis letter parenthesis space> might be better.

The tools used must not be allowed to get in the way of improving the
content.
 
D

Dr John Stockton

JRS: In article <qMszc.3008$0z6.2534@fed1read07>, seen in
What-a-Tool <Die!FrigginSpammersDieDie!@IHate
Spam.Net> posted at Mon, 14 Jun 2004 22:01:59 :
Following is some of my code:
if (eval("document.frmsubmitF.callfunc.checked") == true)
My Problem has been pointed out to me :

But not all of the flaws.

Function eval is needed only as described in FAQ 4.40, and should not be
used otherwise (unless a new class of need exists, in which case please
explain here).

Testing for equality with true is unnecessary, at least almost always :

if (document.frmsubmitF.callfunc.checked) // should work
 
W

What-a-Tool

Function eval is needed only as described in FAQ 4.40, and should not be
used otherwise (unless a new class of need exists, in which case please
explain here).

Testing for equality with true is unnecessary, at least almost always :

if (document.frmsubmitF.callfunc.checked) // should work
links.


Follows is the code I was using:

<form name="frmsubmitinches" id="frmsubmitinches" onsubmit="return
wheretogo();" action="noscript.htm" method="post">


function wheretogo()
{
var intinches = document.frmsubmitinches.txtInches.value

if (intinches.length > 0 && IsNumeric(intinches))
{
if(eval("document.frmsubmitinches.callfunc.checked")==true)
{
alert("Calling ASP Function");
document.frmsubmitinches.action = "calc_feetfunction.asp";
}
if(eval("document.frmsubmitinches.callsub.checked")==true)
{
alert("Calling ASP Sub-Routine");
document.frmsubmitinches.action = "calc_feetsubroutine.asp";
}
if(eval("document.frmsubmitinches.callclass.checked")==true)
{
alert("Calling ASP Class");
document.frmsubmitinches.action = "calc_feetclass.asp";
}
}
else
{
alert ("You must enter a valid numeric value in the inches text box!")
return false;
}


Changed this to :

if("document.frmsubmitinches.callfunc.checked")
{
alert("Calling ASP Function");
document.frmsubmitinches.action = "calc_feetfunction.asp";
}

For some reason, this didn't work. The code traveled thru each of my "If"
statements, calling each of my 3 alert boxes, before finally acting on the
third < document.frmsubmitinches.action = "calc_feetclass.asp"; > to
call my ASP page.
For now, I'm still using the eval function, till I can figure out why it is
acting like this.
 
R

Richard Cornford

What-a-Tool wrote:
Changed this to :

if("document.frmsubmitinches.callfunc.checked")
^ ^
If you put quotes around the property accessor it becomes a string
literal. Non-empty string literals are always true (internally
type-converted to boolean true for the evaluation of the - if -
expression).

For some reason, this didn't work. The code traveled thru each of my
"If" statements, calling each of my 3 alert boxes, before finally
acting on the third < document.frmsubmitinches.action =
"calc_feetclass.asp"; > to call my ASP page.
For now, I'm still using the eval function, till I can figure out why
it is acting like this.

Usenet constantly serves to amaze me that there appear to be so many
people working in the role of programmers (in one sense or another) who
cannot apply logic to problem solving. What you have done in your last
post is present a complete function that was doing what you wanted it to
do (badly, but at least it was functional) and then posted only an
extract from the code that doesn't work. While you might have got lucky
in this case, isn't it obvious that if you don't know what is wrong with
some code you cannot decide which extract might contain the problem. And
if we cannot *see* the code that doesn't work we cannot tell why it
might not be working.

You are really going to have to get around to reading the resources that
I referred you to soon or you are going to end up wasting a lot of your
own time (which is up to you) and a lot of other people's time (which
would be unwelcome).

Richard.
 

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,787
Messages
2,569,630
Members
45,338
Latest member
41Pearline46

Latest Threads

Top