Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Java
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2006, 02:54 AM   #1 (permalink)
j.gohel
Code Monkey
 
Join Date: Apr 2005
Posts: 68
j.gohel is on a distinguished road
A Jsp plus Javascript query

Hi,

I am having the following simple jsp page.:

Code:
<HTML> <HEAD> <TITLE>Hyperlink Javascript Test </TITLE> <script type = "text/javascript"> function testLink(val) { document.write(val); } </script> </HEAD> <BODY> <form name = "test_link"> <table> <% for(int k = 0; k < 5; k++) { String h_Nm = "hName"+k; String a_name = "nm"+k; %> <tr> <td> <input type = "button" name = "<%= h_Nm %>" value ="<%= a_name %>" onClick = "testLink(this.value)"> </td> <tr> <% } %> </table> </form> </BODY> </HTML>
O running this page i will get 5 buttons with their corresponding dynamic values . & on clicking the buttons i will get their respective values displayed.

But i want to do is i want a hyperlink instead of button with same label ,not different labels which i am getting at present which are the values i am getting dynamically, for each of the five hyperlinks but when i click on that hyperlink i should get the dynamic value i am providing at present for the button using javascript.

So please tell how to do this.

Thanks,
Jignesh
__________________
j.gohel is offline   Reply With Quote
Old 03-16-2006, 02:39 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
You're problem is here:
Code:
String h_Nm = "hName"+k; String a_name = "nm"+k;
"k" is assigned in the 'for' loop, and each time through the loop is incremented by one. As a result, h_Nm and a_name are going to reflect that. If you want one to stay the same, then you can't alter it each time through the loop.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-16-2006, 07:10 PM   #3 (permalink)
j.gohel
Code Monkey
 
Join Date: Apr 2005
Posts: 68
j.gohel is on a distinguished road
Hi thanks for the reply.

Sorry i was not able to explain my query properly.

What i want is a HYPERLINK instead of a BUTTON.And as per my code when i click on the hyperlink i should get some unique value associated with that hyperlink & that unique value i want to provide using JSP .So that when i click on a particular hyperlink the unique value provided by me to the hyperlink gets displayed in the browser through my javascript function.So

how to acheive this??
Thanks
__________________
j.gohel is offline   Reply With Quote
Old 03-17-2006, 01:35 AM   #4 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
Ah, it's not a JSP problem then, but an HTML and Javascript problem.

You're looking for
Code:
<a href="javascript:void(0)" onClick="testLink('<%= a_name %>')"><%= h_Nm %></a>
"javascript:void(0)" will allow you to execute Javascript using the anchor tag by basically telling the browser to not follow the hyperlink like it usually would. You can then use the "onClick" or other attribute.

Because you're handing the value directly to the function, you'll need to quote it, but you don't want to break out of the quote used by the "onClick", so you need to use the single quote.

Re-arraign to taste.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript is *not* Java Belisarius Java 0 05-27-2005 06:45 PM
mysql-tomcat-jsp connectivity problem tak2kuldeep Web/Application Servers ( Apache, Tomcat, IIS, JBoss, Websphere, etc... ) 3 05-16-2005 07:31 AM
javascript alert without refreshing? sde HTML, XML, Javascript, AJAX 2 06-30-2004 11:52 AM
Javascriptin' like there ain't no tomorrow saline Saline's Brain Teasers 7 03-12-2003 01:17 AM


All times are GMT -8. The time now is 07:42 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle