Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help - String is not a function

Posted on 2014-07-30
26
Medium Priority
?
193 Views
Last Modified: 2014-07-30
Hi.. I'm trying to add an onclick to HREF. But I get the error
STRING IS NOT A FUNCTION
What's wrong with this?

 <script type="text/javascript">
        function doalert() {
            alert('Test');
            return false;
        }
</script>


It's a classic asp grid..  this is on each line.  Also using Bootstrap
<%

       curValue= "<a href='#editnote'  onclick='return doalert()' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= " & curvalue & " ><b>Edit</b></a>"  
                           
>%
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 6
  • +2
26 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40229188
can you post the rendered code for one of the rows in the grid by viewing the source?
0
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 100 total points
ID: 40229191
Try replacing this:

onclick='return doalert()'

with

onclick='return doalert();'
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229192
Post the rendered HTML
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 400 total points
ID: 40229199
curValue= "<a href='#editnote'  onclick='return doalert()' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id='" & curvalue & "'><b>Edit</b></a>" 

Open in new window

You are missing single quotes around your data-id attribute

As for your error, where are you getting it?
0
 
LVL 1

Author Comment

by:JElster
ID: 40229278
same error

looks like this
<a href='#editnote'  onclick='return doalert();' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= '5206' ><b>Edit</b></a>
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229302
can you attach a file with the entire html generated from your asp page
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 500 total points
ID: 40229303
Then we are not seeing the whole picture.
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229307
I'm with Gary on this one.
0
 
LVL 1

Author Comment

by:JElster
ID: 40229681
Can't run the page stand-alone..

But this works  ?????????

 <script type="text/javascript">
        function doalert() {
          console.log("You clicked ");
            return false;
        }
</script>
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229694
If console.log works then there is no reason alert('Test'); wouldn't work
Is it really?
alert('Test');
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40229708
i just tested the following code on my server and it works fine:

<html>
    <head>
        <script type="text/javascript">
            function doalert() {
                alert('Test');
                return false;
            }
        </script>
    </head>
    <body>
        <%

       curValue = "<a href='#editnote'  onclick='return doalert()' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= " & curvalue & " ><b>Edit</b></a>"   
       response.Write curValue              

        %>
    </body>
</html>

Open in new window


im wondering if there's something else on the page that's blowing it up. are you using the code similar to above or is there other code being used? do you have a link to the page so that we can take a look?
0
 
LVL 1

Author Comment

by:JElster
ID: 40229720
Probably something else blowing it up...  I inherited this mess.
Will see what else I can find.
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229725
string is not a function would normally be an issue in the asp code
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40229746
i just noticed in the original code you posted, you didn't have a correct closing asp tag. the very last line is

>%

when it should be

%>

I assume that's just a typo?

as a test, can you try the code I tested on my server? just throw it as is in a asp page and run it and see if it works for you. if it does, it's something else on the page.
0
 
LVL 1

Author Comment

by:JElster
ID: 40229863
I resolved some JS errors.  So I got further.
But when I try and pass a value.. I get expected token }

I tried something like this

<html>
    <head>
        <script type="text/javascript">
            function doalert(x) {
                alert(x');
                return false;
            }
        </script>
    </head>
    <body>
        <%

      x= '123'

       curValue = "<a href='#editnote'  onclick='return doalert( '& x & ')' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= " & curvalue & " ><b>Edit</b></a>"  
       response.Write curValue              

        %>
    </body>
</html>
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229865
You have an extra apostrophe

alert(x');
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229874
And your string should be

       curValue = "<a href='#editnote'  onclick=""return doalert('"& x & "'')"" class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= '" & curvalue & "' ><b>Edit</b></a>"
0
 
LVL 1

Author Comment

by:JElster
ID: 40229885
getting unexpected token }

No idea why
0
 
LVL 1

Author Comment

by:JElster
ID: 40229890
must be an js error someone where else
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229896
x= '123' in asp needs to be either x="123" or x=123
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 1000 total points
ID: 40229898
you're not matching up your quotes properly, try this

<html>
    <head>
        <script type="text/javascript">
            function doalert( x ) {
                alert(x);
                return false;
            }
        </script>
    </head>
    <body>
        <%
        x = "123"
       curValue = "<a href='#editnote'  onclick='return doalert(""" & x & """)' class='open-EditNoteDialog btn btn-primary' title='Edit Note' data-id= " & curvalue & " ><b>Edit</b></a>"   
       response.Write curValue              

        %>
    </body>
</html>

Open in new window

0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229901
so at this point, re post your changed page source
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40229907
Randy - the value for x and whether it's in quotes or not isn't the issue, the issue was the quotes weren't matching up correctly inside the function call of the curValue variable
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229911
x='123' will error in ASP
0
 
LVL 58

Expert Comment

by:Gary
ID: 40229917
getting unexpected token }

Did you remove the extra quote I pointed out

alert(x');
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229922
I think just a fresh post of the current source will allow us to look at it in its entirety and come to a solution.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question