Ravi Kalla
asked on
<a> tag's "onclick" event not working
in the attached code snippet, onclick event is not working.
When i click on the "SUBMIT" link, i'm able to see the alert box with message "Came HERE". But, "frmNew" is not submitted.
Please let me know if i need to do anything in "fun()" without changing anything in the anchor tag <a>
When i click on the "SUBMIT" link, i'm able to see the alert box with message "Came HERE". But, "frmNew" is not submitted.
Please let me know if i need to do anything in "fun()" without changing anything in the anchor tag <a>
<a id="errBoxCloseLink" href="javascript:void(0);" onclick="fun()" style="color:white;font-weight:bolder;text-decoration:none" title="Close Errors" linkcontrol="ignore">SUBMIT</a>
<script>
function fun()
{
alert("Came HERE");
document.forms["frmNew"].submit();
}
</script>
Hi,
remove the style attribute from the line and use:
<a id="errBoxCloseLink" href="javascript:void(0);" onclick="fun()" class="vClass" title="Close Errors" linkcontrol="ignore">SUBMI T</a>
and then
<style type="text/css">
a.vClass:link {color: blue;}
</style>
Hope this will help you.
Regards
remove the style attribute from the line and use:
<a id="errBoxCloseLink" href="javascript:void(0);"
and then
<style type="text/css">
a.vClass:link {color: blue;}
</style>
Hope this will help you.
Regards
hi,
sorry..you should check if there you defined the form name as commented by ' Valleriani: '
Regards
sorry..you should check if there you defined the form name as commented by ' Valleriani: '
Regards
ASKER
yes... i have already defined the form name as in the attached code
<script>
function fun()
{
alert("Came HERE");
document.forms["frmNew"].submit();
}
</script>
<a id="errBoxCloseLink" href="javascript:void(0);" onclick="fun()" style="color:black;font-weight:bolder;text-decoration:none" title="Close Errors" linkcontrol="ignore">SUBMIT</a>
<form name="frmNew">
</form>
Tested in IE/FF, they seem to be both submitting though. (Page is reloading basicly)
Can we get some more details? Is it tied in another script? Browser version? etc?
Can we get some more details? Is it tied in another script? Browser version? etc?
You might wanna try running these on some other browsers.
ASKER
i'm able to submit by changing the value of "href" to "javascript:fun()"
Hrm, could void(0) be interfering with some browsers? Could try:
<a id="errBoxCloseLink" href="#" onclick="fun()" style="color:white;font-we ight:bolde r;text-dec oration:no ne" title="Close Errors" linkcontrol="ignore">SUBMI T</a>
<a id="errBoxCloseLink" href="#" onclick="fun()" style="color:white;font-we
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ravi_Kalla,
I am going to post this as an objection. The expert's post at http:#a24793997 has the key to your solution. You need return false to follow the script or the browser just goes to the href as a natural next step.
The reason I post this as an objection is it isn't correct to have javascript in the href tag. Depending on the doctype and browser you could even have problems. Even the "javascript: void(0);" code isn't recommended in href anymore. It is better to use # (as suggested in http:#a24793550) or even best to provide an html page that will show some "Javascript needs to be supported" message. The key is the proper fix isn't to move the Javascript but to use return false so the event handling stops.
Let me know if you have a question about this. It is worth changing your code because, even if the comment above was posted after you started closing this, it is the correct answer and way to do this.
b0lsc0tt
I am going to post this as an objection. The expert's post at http:#a24793997 has the key to your solution. You need return false to follow the script or the browser just goes to the href as a natural next step.
The reason I post this as an objection is it isn't correct to have javascript in the href tag. Depending on the doctype and browser you could even have problems. Even the "javascript: void(0);" code isn't recommended in href anymore. It is better to use # (as suggested in http:#a24793550) or even best to provide an html page that will show some "Javascript needs to be supported" message. The key is the proper fix isn't to move the Javascript but to use return false so the event handling stops.
Let me know if you have a question about this. It is worth changing your code because, even if the comment above was posted after you started closing this, it is the correct answer and way to do this.
b0lsc0tt
Should there be a points split?
-Murali*
-Murali*
ASKER
Hi All,
Please check my question. I have mentioned the below statement:
>> Please let me know if i need to do anything in "fun()" without changing anything in the anchor tag
I was not supposed to change anything in the existing anchor tag due to my project restrictions (there are somany dependencies on the JSP file where the anchor tag exists). I have to do the changes only in JavaScript which is specific to my module and I have done it myself after posting it in EE.
Although the comments posted (by Valleriani & MuraliKanth) were some of the possible solutions, they didn't exactly fit my question and so the requirement. Thats why, I have rated the solution with 'B'.
So, I still think that the original rating that I have given is reasonable.
Thanks & Regards,
Ravi Kalla
Please check my question. I have mentioned the below statement:
>> Please let me know if i need to do anything in "fun()" without changing anything in the anchor tag
I was not supposed to change anything in the existing anchor tag due to my project restrictions (there are somany dependencies on the JSP file where the anchor tag exists). I have to do the changes only in JavaScript which is specific to my module and I have done it myself after posting it in EE.
Although the comments posted (by Valleriani & MuraliKanth) were some of the possible solutions, they didn't exactly fit my question and so the requirement. Thats why, I have rated the solution with 'B'.
So, I still think that the original rating that I have given is reasonable.
Thanks & Regards,
Ravi Kalla
<form name="frmNew">
<a id="errBoxCloseLink" href="javascript:void(0);"
</form>
<script>
function fun()
{
alert("Came HERE");
document.forms["frmNew"].s
}
</script>
?