Help - String is not a function

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>"  
                           
>%
LVL 1
JElsterAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
can you post the rendered code for one of the rows in the grid by viewing the source?
0
 
Lee SavidgeCommented:
Try replacing this:

onclick='return doalert()'

with

onclick='return doalert();'
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
GaryCommented:
Post the rendered HTML
0
 
Randy PooleCommented:
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
 
JElsterAuthor Commented:
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
 
Randy PooleCommented:
can you attach a file with the entire html generated from your asp page
0
 
GaryCommented:
Then we are not seeing the whole picture.
0
 
Randy PooleCommented:
I'm with Gary on this one.
0
 
JElsterAuthor Commented:
Can't run the page stand-alone..

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

 <script type="text/javascript">
        function doalert() {
          console.log("You clicked ");
            return false;
        }
</script>
0
 
GaryCommented:
If console.log works then there is no reason alert('Test'); wouldn't work
Is it really?
alert('Test');
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
JElsterAuthor Commented:
Probably something else blowing it up...  I inherited this mess.
Will see what else I can find.
0
 
Randy PooleCommented:
string is not a function would normally be an issue in the asp code
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
JElsterAuthor Commented:
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
 
GaryCommented:
You have an extra apostrophe

alert(x');
0
 
GaryCommented:
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
 
JElsterAuthor Commented:
getting unexpected token }

No idea why
0
 
JElsterAuthor Commented:
must be an js error someone where else
0
 
Randy PooleCommented:
x= '123' in asp needs to be either x="123" or x=123
0
 
Randy PooleCommented:
so at this point, re post your changed page source
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
Randy PooleCommented:
x='123' will error in ASP
0
 
GaryCommented:
getting unexpected token }

Did you remove the extra quote I pointed out

alert(x');
0
 
Randy PooleCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.