• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Changing href dynamically

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi - I'm trying to use some Javascript validation before letting the user validate away from a JSP page using a link. Basically the link is controlled by a serlvet but the validation is in Javascript and looks something like this

<a href = "javascript:if (aFunction() == true) <%JSP to take to to page%>".

Unfortunately it doesn't work - the Javascript function is evaluated but the JSP is ignored, I guess because it should have been evaluated on the server before the Javascript runs. I've tried a few variations like putting the JSP in the function but it still doesn't work. Is there anyway around this, like using the onClick event or something?

Thanks,

Matt
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one way:

<a href="<%JSP LINK%>" onclick="return aFunction()">BLAH BLAH</a>

Eric
 
reply
    Bookmark Topic Watch Topic
  • New Topic