Solved

Help - String is not a function

Posted on 2014-07-30
26
179 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
  • 8
  • 6
  • 6
  • +2
26 Comments
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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 25 total points
Comment Utility
Try replacing this:

onclick='return doalert()'

with

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

Expert Comment

by:Gary
Comment Utility
Post the rendered HTML
0
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
can you attach a file with the entire html generated from your asp page
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 125 total points
Comment Utility
Then we are not seeing the whole picture.
0
 
LVL 21

Expert Comment

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

Author Comment

by:JElster
Comment Utility
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
Comment Utility
If console.log works then there is no reason alert('Test'); wouldn't work
Is it really?
alert('Test');
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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
Comment Utility
string is not a function would normally be an issue in the asp code
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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
Comment Utility
You have an extra apostrophe

alert(x');
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
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
Comment Utility
getting unexpected token }

No idea why
0
 
LVL 1

Author Comment

by:JElster
Comment Utility
must be an js error someone where else
0
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
x= '123' in asp needs to be either x="123" or x=123
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 250 total points
Comment Utility
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
Comment Utility
so at this point, re post your changed page source
0
 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
x='123' will error in ASP
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
getting unexpected token }

Did you remove the extra quote I pointed out

alert(x');
0
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now