Empty Anchors and the Fish Theory

liunx

Guest
In IE, you can do something like:<br />
<br />
<a onClick="Some Action"><img></img></a><br />
<br />
and it will allow you to invoke the action when you click on that image.<br />
<br />
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?<!--content-->Originally posted by Geat <br />
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.<!--content-->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.<br />
<br />
Perhaps if you explain why you don't want to use an HREF in your link, we can figure out an appropriate work-around.<!--content-->Basically, I've got a form value called "submitted", that is set to the ID of the page.<br />
<br />
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.<br />
<br />
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.<br />
<br />
That make sense?<!--content-->Originally posted by Geat <br />
That make sense?No, not really.<br />
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?<!--content-->Okay, yeah, I meant I've got a hidden value form field called submitted...<br />
<br />
The form's kinda long and complicated to show here, but the basic parts are...<br />
<br />
<form name="the_form" action="actionpage.php" method="post" onSubmit="return DoSubmit();"><br />
<input type="hidden" name="submitted" value="2" /><br />
<br />
Then the bit that toggles the display of the rest of the form is:<br />
<br />
<select name="authoriseperson" onchange="document.the_form.submitted.value = '2';submit()" size="1"><option selected>Yes</option><option>No</option></select><br />
<br />
And the end bit:<br />
<br />
<img src=http://www.webdeveloper.com/forum/archive/index.php/"images/but_form_next.jpg" border="0" onClick="the_form.submitted.value ='3';submit()"><br />
<br />
Which works in IE perfectly...<br />
<br />
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.<!--content-->Your problem is more likely with scope. NS 4 needs a little more information than IE. Give these mods a go:<br />
<br />
<select name="authoriseperson" <br />
onchange="this.form.submitted.value='2';this.form.submit()" size="1"><br />
<option selected>Yes</option><br />
<option>No</option><br />
</select><br />
...<br />
<img src=http://www.webdeveloper.com/forum/archive/index.php/"images/but_form_next.jpg" border="0" <br />
onClick="the_form.submitted.value='3';submit()" <br />
onload="if(document.layers){this.onmousedown=function () {document.the_form.submitted.value='3';document.the_form.submit();return false}}"><br />
<br />
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.<!--content-->Well done mate - works a treat!<br />
<br />
Cheers!<!--content-->or you could just do <a href=http://www.webdeveloper.com/forum/archive/index.php/"#" onClick etc><!--content-->Doing that doesn't submit the page like Gil's answer does, it just takes you to the top - which is no good...<!--content-->Originally posted by Geat <br />
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:<br />
<br />
<a href=http://www.webdeveloper.com/forum/archive/index.php/"#" onclick="...;return false"><br />
<br />
With the "return false" at the end, it won't go anywhere unless the user has javascript disabled.<!--content-->But in answer to your question:<br />
<br />
Originally posted by Geat <br />
In IE, you can do something like:<br />
<br />
<a onClick="Some Action"><img></img></a><br />
<br />
and it will allow you to invoke the action when you click on that image.<br />
<br />
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? <br />
<br />
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.<br />
<br />
Just trying to answer the question that was asked...<!--content-->It doesn't work in Netscape, that's why I posted the query in the first place.<br />
<br />
But it's all good, Gil gave me a workaround which worked a treat.<!--content-->
 
Back
Top