Click to See Complete Forum and Search --> : Empty Anchors and the Fish Theory


Geat
02-11-2003, 05:42 AM
In IE, you can do something like:

<a onClick="Some Action"><img></img></a>

and it will allow you to invoke the action when you click on that image.

However, Netscape 4.x doesn't allow an anchor to exist without an entry in the HREF part, which I don't want! Is there a way to overcome this?

Charles
02-11-2003, 05:48 AM
Originally posted by Geat
Is there a way to overcome this? Yes, make your page work equally well without JavaScript and then don't worry about it. Consider, something like 1% of users are using Netscape 4 and yet 10% of users do not use JavaScript at all.

gil davis
02-11-2003, 06:09 AM
NS 4 requires a link to have an HREF. Otherwise it is an anchor. NS 4 does not support mouse events on an anchor, only on a link.

Perhaps if you explain why you don't want to use an HREF in your link, we can figure out an appropriate work-around.

Geat
02-11-2003, 06:15 AM
Basically, I've got a form value called "submitted", that is set to the ID of the page.

If the user selects "No" from one of the combos on the form, the rest of the form is irrelevant - so the page reloads without this superfluous UI (via PHP). Obviously, when the user changes this combo, the value of "submitted" is changed to the ID of the current page.

When the user clicks "next", however (which is where this click event comes in), the page ID (value of submitted) needs to be set to the next page, which is the javascript I'm trying to invoke.

That make sense?

gil davis
02-11-2003, 06:21 AM
Originally posted by Geat
That make sense?No, not really.
I've got a form value called "submitted", that is set to the ID of the page.Forms don't have values, per se. Form elements have values. What element are you talking about? How about showing the HTML for the form with the "next" thingy?

Geat
02-11-2003, 06:28 AM
Okay, yeah, I meant I've got a hidden value form field called submitted...

The form's kinda long and complicated to show here, but the basic parts are...

<form name="the_form" action="actionpage.php" method="post" onSubmit="return DoSubmit();">
<input type="hidden" name="submitted" value="2" />

Then the bit that toggles the display of the rest of the form is:

<select name="authoriseperson" onchange="document.the_form.submitted.value = '2';submit()" size="1"><option selected>Yes</option><option>No</option></select>

And the end bit:

<img src="images/but_form_next.jpg" border="0" onClick="the_form.submitted.value = '3';submit()">

Which works in IE perfectly...

You should note that this script is used to generate all 10 pages of the form, with a case statement that generates the correct subsection of the form.

gil davis
02-11-2003, 06:37 AM
Your problem is more likely with scope. NS 4 needs a little more information than IE. Give these mods a go:

<select name="authoriseperson"
onchange="this.form.submitted.value='2';this.form.submit()" size="1">
<option selected>Yes</option>
<option>No</option>
</select>
...
<img src="images/but_form_next.jpg" border="0"
onClick="the_form.submitted.value='3';submit()"
onload="if(document.layers){this.onmousedown=function () {document.the_form.submitted.value='3';document.the_form.submit();return false}}">

There is another wrinkle you need to handle in NS 4. Using JS to submit() the form will not trigger the onsubmit handler of the form. So, your validation stuff will not run like you think it should.

Geat
02-11-2003, 06:42 AM
Well done mate - works a treat!

Cheers!

jpmoriarty
02-11-2003, 06:47 AM
or you could just do <a href="#" onClick etc>

Geat
02-11-2003, 07:49 AM
Doing that doesn't submit the page like Gil's answer does, it just takes you to the top - which is no good...

gil davis
02-11-2003, 07:57 AM
Originally posted by Geat
Doing that doesn't submit the page like Gil's answer does, it just takes you to the top - which is no good... You have to cancel the standard click action:

<a href="#" onclick="...;return false">

With the "return false" at the end, it won't go anywhere unless the user has javascript disabled.

jpmoriarty
02-12-2003, 02:56 AM
But in answer to your question:

Originally posted by Geat
In IE, you can do something like:

<a onClick="Some Action"><img></img></a>

and it will allow you to invoke the action when you click on that image.

However, Netscape 4.x doesn't allow an anchor to exist without an entry in the HREF part, which I don't want! Is there a way to overcome this?

It gives you an anchor with a valid working entry (which appears to do nothing) in the HREF section and allows you to add your own onClick, and will therefore work with both Netscape and IE.

Just trying to answer the question that was asked...

Geat
02-12-2003, 03:03 AM
It doesn't work in Netscape, that's why I posted the query in the first place.

But it's all good, Gil gave me a workaround which worked a treat.