Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use hyperlink to submit a form via javascript

Status
Not open for further replies.

jeffcullina

Programmer
May 13, 2002
80
US
I have a hyperlink set up as follows:

<a href=&quot;NewPage&quot; class=&quot;Blue&quot;>New Page</a>

I would like for the link to go to a javascript function while maintaining the style of the hyperlink (color and mouseover properties. I tried:

<b style=&quot;Blue&quot; onclick=&quot;fun()&quot;>New Page</b>

This does go to the javascript function, but it does not keep the Blue formatting. I also tried replacing STYLE with CLASS, but CLASS is not an attribute of <b>. Do I have to redefine my Blue formatting as a STYLE rather than a CLASS? If I do, will I be able to keep my rollover formatting? Is there a better way to go about all of this?
 
1) Why would you want the link to go into JS function??
2) You want to keep the STYLE when the function is called?? Why would it loose the style?? As my understanding of STYLE goes, if you define all the A: tags in style, the STYLE will be used as long as it is called... I have not failed; I have merely found 100,000 different ways of not succeding...
 
I found the solution. Simply replace the page name defined in HREF with &quot;javascript:fun()&quot;. I am doing this so I can submit the page before going to the next page because I want to store the values in the form. If the user uses the hyperlink, he will eventually find his way back into the page, at which point the values that have already been entered will be restored. The actual submit button on that page has a different function. The solution is as follows:

Replace
<a href=&quot;NewPage&quot; class=&quot;Blue&quot;>New Page</a>

With
<a href=&quot;javascript:fun()&quot; class=&quot;Blue&quot;>New Page</a>
 
First - in the anchor tag <a href=&quot;NewPage&quot; class=&quot;Blue&quot;>New Page</a> &quot;Blue&quot; must have been previously defined as an element of the anchor tag: something like a.Blue {font-family: Arial; font-weight: bold; font-size: 10px}. Without this, &quot;Blue&quot; is meaningless.

Second, it appears that your anchor tag would take you to a new page. If this is the case, then you'd need to apply the a.Blue spec again to have a &quot;Blue&quot; hyperlink on the new page.

By the way, <b style=&quot;Blue&quot; onclick=&quot;fun()&quot;>New Page</b> is not a vaild hyperlink. It may work but it will cause you grief down the road. There's always a better way...
 
<a href=&quot;NewPage&quot; class=&quot;Blue&quot; onClick=&quot;javascript: subForm()&quot;>New Page</a>

<script>
function subForm(){
//validate form here first
document.myForm.action = &quot;page2.asp&quot;
document.myForm.method = &quot;post&quot;
document.myForm.target = &quot;_blank&quot; //if you want a new window
document.myForm.submit()
}
</script> Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top