Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help - String is not a function

Posted on 2014-07-30
26
Medium Priority
?
197 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 34

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 34

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 34

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 34

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 34

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
Suggested Courses

916 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