473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

simple but baffling javascript prob

hi folks,
I'm using the .Net framework 1.1 with ASP.net and C#:

this is what I'm trying to do...

I've got a repeater template working that creates a hyperlink with a
javascript function call embedded inside it
when the user clicks on the link, it populates a textbox with a value
specific to that link (i.e a person's ID)...I can make this work in a
standalone browser window, but I'm trying to stuff this functionality at run
time into the repeater's template like so:
<asp:Repeater id="repPersonnel" runat="server">
<HeaderTemplate>
<h1>Returned Names</h1>
</HeaderTemplate>

<ItemTemplate>
<a href='#' onClick="passValue('" +
<%# DataBinder.Eval(Container.DataItem,"file_no") %> +
"');return false" >
<%# DataBinder.Eval(Container.DataItem,"sort_nm") %>
</a>
<p />
</ItemTemplate>

I realize this is a bit opaque but the output should look like this:

<input type="text" id="txtChosenvalue" name="txtChosenvalue" />
<p/>
<a href="" onClick="passValue('1000234');return false">Adams, Fred</a>
<p/>
<a href="" onClick="passValue('2000234');return false">Williams, Barry</a>

the passValue function looks like this:
function passValue(theid)
{
document.getElementById("txtChosenvalue").value=th eid;
}

the error I'm getting at run time in the browser window is a Javascript error:
Unterminated string constant

and it's to do with trying to stuff the dynamically returned id as a string
constant into the javascript function call as a parameter, inside the
hyperlink.

the problem is, I can't see how it's unterminated, I've got the return value
safely cradeled between two single quotes like so:

<a href='#' onClick="passValue('" +
<%# DataBinder.Eval(Container.DataItem,"file_no") %> +
"');return false" >
any ideas?

Thanks and regards in advance,
CharlesA


Mar 22 '06 #1
2 1242
I've got it to work! if anyone is interested it's because I was labouring
under the misapprehension that I had to concatenate the whole thing the way
you would with normal string manipulation... but instead of this:
<a href='#' onClick=
"passValue('"
+
<% # DataBinder.Eval(Container.DataItem,"file_no")%> #
+
"');return false" >

<%# DataBinder.Eval(Container.DataItem,"sort_nm") %> </a>

what is required is just this:
<a href='#' onClick=
"passValue('<%# DataBinder.Eval(Container.DataItem,"file_no")%> ');return
false" >
<%# DataBinder.Eval(Container.DataItem,"sort_nm") %> </a>

you have to take out the + concatenation operator and the extra quotes and
just give what the HTML stream is literally expecting

I only managed to figure it out because my mind went into 'think clearly
about how your formulate your problem and explain it to others if you're
going to do a post' mode. So it was helpful to post it anyway

Cheers,
CharlesA
Mar 22 '06 #2
This will work. Just a little tip, look at the source of the rendered
page and you can usually see what the problem is in cases like this.

<asp:Repeater id=Repeater1 runat="server">
<ItemTemplate>
<a href='javascript:passValue("
<%# DataBinder.Eval(Container.DataItem,"file_no") %>")'>
<%# DataBinder.Eval(Container.DataItem,"sort_nm")
%><a/><br>
</ItemTemplate>
</asp:Repeater>

If you had looked at the rendered output from your statements you would
have seen this:
<a href='#' onClick="passValue('" + Fred + "');return false" >1 <a/>

Fred (my bs data) would be the unterminated string causing the problem.

Hope this helps.

Mar 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sasha Shevelev | last post by:
Hi there, I can;t believe no one else has had this prob but here goes... I add some javascript into my page and asp.net sometimes (not always) puts the js into my page with a line break...
5
by: Steve | last post by:
Hi, I have a private website for 20 people that is similar to a web email client like hotmail. There are two frames, one on the left with links for "New", "History", "Todays" and a frame on the...
2
by: Fabian | last post by:
This javascript is meant for learning language vocabulary, specifically colours on this example. However, when I use images in the mtWord array, it breaks when checking for correct answers. It...
8
by: Michelle | last post by:
I have tried every variation of the "onchange" statement below without any actual reloading of the page: The FireFox javaScript Console reports the following message: Error: missing : in...
7
by: Monty | last post by:
Something odd is happening. Scripts on several sites that collect form data, save it to a DB, then redirect the user to another page are slowing to a crawl during the redirect using the header()...
2
by: noddy | last post by:
In both IE7 and FF2(using firebug) I get the same error. I have a page that displays work contacts' details within a <DIV class = "contactBase" >. The div has a header area <div...
0
by: Greg Corradini | last post by:
Hello all, I'm having trouble inserting an SQL selection into a new MS Access table. I get a parameter error on my insert statement when I try this (see below for code and error msg). I'm not sure...
9
by: djconner | last post by:
I'm a total neophyte in Javascript, trying to hack something together fast, and run into something that I can't understand at all. Two loops appear in sequence. The idea is that arrQuestions...
10
by: LayneMitch via WebmasterKB.com | last post by:
Hello. I'm trying to figure out why this isn't working... <html><head><title>Prob.11</title> <script type="text/javascript"> function attachHandlers { var...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.