Solved

Call javascript function gives type mismatch ?

Posted on 2005-04-25
10
922 Views
Last Modified: 2012-08-14
Please help me asap.  Why Am I getting this ?

Please help if you can see any error.

<%For i = 1 To nMoreRows1%>
                    <TR>
                              <TD height="22"><INPUT type="text" ID="Task<%=i %>" NAME="Task<%=i %>"></TD>
                              <TD height="22">
                         <%For j = 1 To nMoreRes1%>
                               <div id = "Task<%=i %>Res<%=j%>"></div>
                         <%
                         call cmdAddRes(i,j) <---------------TYPE MSMATCH ERROR
                         next%>
                         
                         
                              <a href="#top" name="lnkAddresource" OnClick="cmdAddRes(task<%=i %>, <%=j%>)">+ add resources</a>
                         
                              </TD>
                         
                              <TD height="22">
                         <%For j = 1 To nMoreRes1%>
                               <div id = "Task<%=i %>Hr<%=j%>"></div>
                         <%next%>
                         </TD>
                    </TR>
                         
                    <%
                    next%>

function cmdAddRes(obj,obj2)
{
var resname;
var el = document.createElement('input')
el.type = "text";
el.name = "Task" + obj + "Res" + obj2
resname = "Task" + obj + "Res" + obj2
document.getElementById(resname).appendChild(el);
var br = document.createElement('br')
document.getElementById(resname).appendChild(br);
var hrname;
var el2 = document.createElement('input')
el2.type = "text";
el2.name = "Task" + obj + "Hr" + obj2
hrname =  "Task" + obj + "Hr" + obj2
document.getElementById(hrname).appendChild(el2);
var br2 = document.createElement('br')
document.getElementById(hrname).appendChild(br2);
}
0
Comment
Question by:suran78
  • 5
  • 3
  • 2
10 Comments
 
LVL 15

Expert Comment

by:justinbillig
Comment Utility
you can't set the type attribute of an html element, it is read only
0
 
LVL 25

Expert Comment

by:archrajan
Comment Utility
call cmdAddRes(i,j)
shud be
cmdAddRes('i','j')
0
 
LVL 25

Expert Comment

by:archrajan
Comment Utility
justinbillig,
But in this case we r creating elements dynamically, and hence u can set the type and it wud work
0
 
LVL 15

Expert Comment

by:justinbillig
Comment Utility
I have a question, instead of creating the elements in javascript, why not create them in ASP?
0
 

Author Comment

by:suran78
Comment Utility
How ? Please give me the code in ASP to do the same.

call cmdaddres('i','j') is not working.  ' is a comment symbol in asp/vb
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 25

Expert Comment

by:archrajan
Comment Utility
to call javascript u shud put them between the <script></script> tags. anyways.
0
 

Author Comment

by:suran78
Comment Utility
please help me in constructing the javasript tag in asp, I tried and I think I missed quotes:

<%For j = 1 To nMoreRes1%>
                                     <div id = "Task<%=i %>Res<%=j%>"></div>
                              <%
                              

                              call cmdAddRes("i","j") ----->   "<script type=" & "text/javascript">
cmdAddRes(i,j) ;
</script> ???

                              next%>

0
 
LVL 25

Accepted Solution

by:
archrajan earned 125 total points
Comment Utility
TAKE THE call keyword out


u dont need the <% %> at all

just where u want to call you can call it like this

<script>
cmdAddRes("i","j");
</script>

or u shud call it with some event handler like this onload or onclick = "cmdAddRes('i','j');"
0
 

Author Comment

by:suran78
Comment Utility
I am getting this error now, object expected for teh javasript function

This is teh code.  I have to call it in, i cannot use it anywhere else for onload or onclick

<%For j = 1 To nMoreRes1%>
                                     <div id = "Task<%=i %>Res<%=j%>"></div>
                                     <script>
                                          cmdAddRes("i","j");
                                    </script>

                              <%next%>
                              
0
 
LVL 25

Expert Comment

by:archrajan
Comment Utility
post the generated code for this
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now