View Full Version : Javascript client-side scripting
kuchiv
01-07-2003, 02:55 AM
Can help me in this regard?. Its urgent.
I have a asp file. Some html tags are embedded in it. Some data is posted to the database from this html page via .asp file. In it, I have a checkbox. As soon as its, checked, then a text box should be displayed. If its not checked, then couple of dropdown boxes should be displayed. How to do it?
I have given it as
<input type="checkbox" name="emergency" onclick=click() value="emergency"><BR>
But the event is not fired at that time. Whatz the problem?. I cant send the complete code?. what possible error can this be?
glenngv
01-07-2003, 03:14 AM
click is a reserved word in javascript. try renaming it.
kuchiv
01-07-2003, 03:20 AM
I have tried it changing the name from click to another name. but its still not working.
glenngv
01-07-2003, 03:23 AM
pls post the content of that script.
Originally posted by glenngv
click is a reserved word in javascript. try renaming it.
No it's not. (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/keywords.html#1004016)
kuchiv
01-07-2003, 03:39 AM
checkbox form:
<FORM id="formMain" name="formMain" ACTION=QCreateReviewSaveRecord.asp>
the rest of the related code is:
<td><SELECT NAME="ProcessCode" id="ResourceSelection" onchange="newWindow('QResourceItemSelect.asp?listTarget=ItemDisplay&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ItemDisplay=ItemDisplay&ItemValue=ItemCode&<%=ExtraStr%>','window10',optionSelected(document.formMain.ProcessCode)); newWindow('QCatActList.asp?<%=ExtraStr%>&typeCode=' + optionSelected(document.formMain.TypeCode) + '&locationCode=' + optionSelected(document.formMain.LocationCode) + '&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ODBC=<%=ODBC%>&NewODBC=<%=NewODBC%>&catlistTarget=CategoryCode&actlistTarget=ActionCode&ItemValue=SubItem','window3',optionSelected(document.formMain.TypeCode));"><%Call WriteProcessList(conn)%> </select> <%writeFilterButtons("ResourceSelection")%></td>
</TR>
<TR>
<td><select NAME="ItemDisplay" VALUE="" onchange="document.formMain.SubItem.value = this.value; newWindow('QResourceAllocatedEmp.asp?TitleTarget=TitleCode&EmpTarget=EmployeeCode&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ItemCode=' + optionSelected(document.formMain.ItemDisplay) + '&<%=ExtraStr%>','window11',optionSelected(document.formMain.ItemDisplay));"><option value="(none)">(None)</option></select> <%writeFilterButtons("ItemDisplay")%><span id="ItemDisplaywaitmsg" style="display:none"> Loading...</span></td>
<input TYPE="hidden" NAME="SubItem" VALUE="">
</TR>
<%End If%>
<TR>
<TH><%=ipub.Component.Captions("Type")%>:</TH>
<TD ><SELECT NAME=TypeCode id=ReviewType onchange="newWindow('QCatActList.asp?<%=ExtraStr%>&typeCode=' + optionSelected(document.formMain.TypeCode) + '&locationCode=' + optionSelected(document.formMain.LocationCode) + '&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ODBC=<%=ODBC%>&NewODBC=<%=NewODBC%>&catlistTarget=CategoryCode&actlistTarget=ActionCode&ItemValue=SubItem','window4',optionSelected(document.formMain.TypeCode));">
<%Call icon.WriteTypeList(Response, "(None)", "")%>
</SELECT> <%writeFilterButtons("ReviewType")%><span id="ReviewTypewaitmsg" style="display:none"> Loading...</span></TD>
</TR>
<tr><td colspan=2> </td></tr>
<TR>
<TH ><%=ipub.Component.Captions("Category")%>:</TH>
<TD ><SELECT NAME=CategoryCode>
<%Call icon.WriteCategoryList(Response, "(None)", "")%>
</SELECT> <%writeFilterButtons("CategoryCode")%><span id="CategoryCodewaitmsg" style="display:none"> Loading...</span></TD>
</TR>
<TR>
<TH ><%=ipub.Component.Captions("Action")%>:</TH>
<TD ><SELECT NAME=ActionCode>
<%Call icon.WriteActionList(Response, "(None)", "")%>
</SELECT> <%writeFilterButtons("ActionCode")%><span id="ActionCodewaitmsg" style="display:none"> Loading...</span></TD>
</TR>
<TR>
<TH ><%=ipub.Component.Captions("Internal Reference")%>:</TH>
<TD ><input TYPE="TEXT" NAME="InternalRef">
</TR>
<%If CustomCode = "CUSCAL" Then%>
<TR>
<TH ROWSPAN=2><%=ipub.Component.Captions("Resource")%>:</TH>
<td ><SELECT NAME="ProcessCode" id="ResourceSelection" onchange="newWindow('QResourceItemSelect.asp?<%=ExtraStr%>&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ODBC=<%=ODBC%>&NewODBC=<%=NewODBC%>&ItemDisplay=ItemDisplay&ItemValue=SubItem','window5',optionSelected(document.formMain.ProcessCode));"><%Call iCon.c_CUSCAL_WriteProcessList(response, "(None)", 0)%></select> <%writeFilterButtons("ResourceSelection")%></td>
</TR>
<TR>
<td ><input TYPE="TEXT" NAME="ItemDisplay" VALUE=""><INPUT TYPE="BUTTON" VALUE="Change" onClick="newWindow('QResourceItemSelect.asp?<%=ExtraStr%>&resourceCode=' + optionSelected(document.formMain.ProcessCode) + '&ODBC=<%=ODBC%>&ItemDisplay=ItemDisplay&ItemValue=SubItem','window6',document.formMain.ProcessCode.value)" id=BUTTON1 name=BUTTON1></td>
<input TYPE="HIDDEN" NAME="SubItem" VALUE="">
</TR>
<TR>
<TH COLSPAN=2></TH>
</TR>
<TR>
<TH ><%=ipub.Component.Captions("Emergency")%>:</TH>
<TD><input type="checkbox" name="emergency" onchange=click1() value="emergency"><BR>
<script language="Javascript">
function click1()
{
alert("checked");
}
</script>
<!--<INPUT type="checkbox" id="chk_emergency" name="chk_checkbox1" onclick="click()">-->
</TR>
<TR>
<TH ><%=ipub.Component.Captions("Allocate To")%>:</TH>
</TR>
<TR>
<INPUT TYPE=HIDDEN NAME=TitleCode VALUE="">
<TH ><%=ipub.Component.Captions("Employee")%>:</TH>
<TD class="evenrow" ><SELECT NAME=EmployeeCode>
<%Call icon.WriteEmployeeList(Response, "(None)", "")
%>
</SELECT></TD>
</TR>
<%Else%>
<tr><td colspan=2> </td></tr>
<%If ipub.Database.GetInformationBoolean("Hide Title For Employee Selection", "FALSE") Then%>
<TR>
<INPUT TYPE=HIDDEN NAME=TitleCode VALUE="">
<TH class="headrow" ><%=ipub.Component.Captions("Allocate To")%>:</TH>
<TD class="evenrow" ><SELECT NAME=EmployeeCode>
<%Call icon.WriteEmployeeList(Response, "(None)", "")%>
</SELECT> <%writeFilterButtons("EmployeeCode")%></TD>
</TR>
<%Else%>
<TR>
<TH class="headrow" ROWSPAN=2><%=ipub.Component.Captions("Allocate To")%>:</TH>
<td class="evenrow" ><select onchange="newWindow('QTitleEmployeeSelect.asp?<%=ExtraStr%>&titlecode=' + optionSelected(document.formMain.TitleCode) + '&ODBC=<%=ODBC%>&NewODBC=<%=NewODBC%>&listTarget=EmployeeCode&EmpValue=EmployeeCode','window7',optionSelected(document.formMain.TitleCode));" NAME="TitleCode">
<%Call icon.WriteTitleList(response, "(None)", 0)%>
</select> <%writeFilterButtons("TitleCode")%> <span id="TitleCodewaitmsg" style="display:none"> Loading...</span></td>
</TR>
<TR>
<td class="evenrow" ><select NAME="EmployeeCode" VALUE=""><option value="(none)">(None)</option></select> <%writeFilterButtons("EmployeeCode")%> <span id="EmployeeCodewaitmsg" style="display:none"> Loading...</span></td>
</TR>
<%End If
If ipub.Database.GetInformationBoolean("Signoff in Create Review", "FALSE") Then
If ipub.Database.GetInformationBoolean("Hide Title For Employee Selection", "FALSE") Then%>
<TR>
<INPUT TYPE=HIDDEN NAME=SignoffTitleCode VALUE="">
<TH class="headrow" ><%=ipub.Component.Captions("Signoff")%>:</TH>
<TD class="evenrow" ><SELECT NAME=SignoffEmployeeCode>
<%Call icon.WriteEmployeeList(Response, "(None)", "")%>
</SELECT> <%writeFilterButtons("SignoffEmployeeCode")%></TD>
</TR>
<%Else%>
<TR>
<TH class="headrow" ROWSPAN=2><%=ipub.Component.Captions("Signoff")%>:</TH>
<td class="evenrow" ><select onchange="newWindow('QTitleEmployeeSelect.asp?<%=ExtraStr%>&titlecode=' + optionSelected(document.formMain.SignOffTitleCode) + '&ODBC=<%=ODBC%>&NewODBC=<%=NewODBC%>&listTarget=SignoffEmpDisplay&EmpValue=SignoffEmployeeCode','window8',optionSelected(document.formMain.SignOffTitleCode));" NAME="SignOffTitleCode">
<%Call icon.WriteTitleList(response, "(None)", 0)%>
</select> <%writeFilterButtons("SignoffTitleCode")%></td>
</TR>
<TR>
<td class="evenrow" ><select onchange="document.formMain.SignoffEmployeeCode.value = this.value" class="inputmedium" NAME="SignoffEmpDisplay" VALUE=""><option value="(none)">(None)</option></select> <%writeFilterButtons("SignoffEmpDisplay")%><span id="SignoffEmpDisplaywaitmsg" style="display:none"> Loading...</span></td>
<input TYPE="HIDDEN" NAME="SignoffEmployeeCode" VALUE="">
</TR>
<%End If
End If
End If%>
<tr><td colspan=2> </td></tr>
<TR>
<TH class="headrow" ><%=ipub.Component.Captions("Proposed Completion Date")%>:</TH>
<TD class="evenrow" ><input class="inputmedium" TYPE="TEXT" NAME="ProposedTargetDate"> <span id="calbutton" onClick="newWindow('UDTCalendar.asp?<%=ExtraStr%>&obj=ProposedTargetDate','window9','')" style="cursor:hand;text-decoration:underline;" valign="center"><small>Calendar</small></span></TD>
</TR>
<%if mid(ipub.Component.Database.GetInformation("Review Discussion Options","1111110"),1,1) = "1" then%>
<TR>
<TH class="headrow" ><%=ipub.Component.Captions("")%>:</TH>
<TD class="evenrow" ><TEXTAREA class="inputmedium" NAME=Details COLS=<%=ipub.Component.Database.TextAreaColumns%> ROWS=<%=ipub.Component.Database.TextAreaRows%>></TEXTAREA></TD>
</TR>
<%end if%>
<tr><td colspan=2> </td></tr>
<TR>
<TH class="headrow"> </th><td ><INPUT TYPE=SUBMIT VALUE="Save Issue" onclick="return(validateFields());" id=BUTTON3 name=BUTTON3></Td>
</TR>
</FORM>
<tr><td colspan=2> </td></tr>
<tr><td colspan=2> </td></tr>
</TABLE>
<br>
<%PageFooter
Else%>
<!-- #INCLUDE FILE="../includes/global_security.inc" -->
<%End If
Else
InvalidComponent
End If
</BODY>
</HTML>
glenngv
01-07-2003, 03:47 AM
but what is this, jkd?
<input type="checkbox" name="emergency" onclick="alert(typeof click)" value="emergency">
click is a method for input elements like checkbox, file, radio, reset, submit
glenngv
01-07-2003, 03:50 AM
kuchiv, the alert doesn't come up when you click the checkbox?
<input type="checkbox" name="emergency" onchange=click1() value="emergency"><BR>
<script language="Javascript">
function click1()
{
alert("checked");
}
</script>
Originally posted by glenngv
but what is this, jkd?
<input type="checkbox" name="emergency" onclick="alert(typeof click)" value="emergency">
click is a method for input elements like checkbox, file, radio, reset, submit
A method name does not constitute a reserved word, merely an identifier in use. In this case, the checkbox element inherits a click() method, but "click" itself is not reserved, since it can be used freely in other namespaces.
kuchiv
01-07-2003, 03:56 AM
Now what is the exact problem with the code?. What changes am I supposed to do to the above code?
glenngv
01-07-2003, 04:03 AM
Originally posted by jkd
A method name does not constitute a reserved word, merely an identifier in use. In this case, the checkbox element inherits a click() method, but "click" itself is not reserved, since it can be used freely in other namespaces.
but it can't be used inside event handlers in html elements that inherit a click() method.
kuchiv, the alert should come up when you click the checkbox.
kuchiv
01-07-2003, 04:07 AM
OK,
when i click or check the checkbox, the event should be fired. What exactly should be done at that stage. I have even tried changing the name of the method from click() to click1(). Even then its not working. what is the problem?.
Originally posted by glenngv
but it can't be used inside event handlers in html elements that inherit a click() method.
Really? (http://www.jasonkarldavis.com/click.html)
kuchiv
01-07-2003, 04:15 AM
I agree with u. but now, coming to my particular doubt, what am I supposed to do, to complete this task successfully.
glenngv
01-07-2003, 06:00 AM
Originally posted by jkd
Really? (http://www.jasonkarldavis.com/click.html)
after the first alert, it displays error "Object doesn't support this action" in IE5.5.
so it fails in this statement:
click = 1;
kuchiv, this works for me:
<input type="checkbox" name="emergency" onclick="click1()" value="emergency"><BR>
function click1(){
alert('test')
}
if the function name is click(), the function is not fired.
in your case, is the function click1() not called when you click the checkbox?
Originally posted by glenngv
after the first alert, it displays error "Object doesn't support this action" in IE5.5.
Works fine in my primary web browser, Mozilla. This is actually interesting, as you should be able to reassign the method in IE.
So, I leave my argument at it works in a real Javascript environment :p, and that is a very interesting discrepancy in Internet Explorer.
kuchiv
01-07-2003, 06:55 AM
No infact I am checking the check box. but no action performed. Can you go thru the code and then let me know what has gone wrong?. I am not able to make it.
glenngv
01-07-2003, 07:12 AM
It will work if the button had been like this:
<script>
click=2;
</script>
<input type="button" value="Watch me use click" onclick="alert(click); window.click = 1; alert(window.click);"/>
reminds me of this thread:
http://codingforums.com/showthread.php?s=&threadid=8748
whew! I had a hard time searching that thread :(
kuchiv
01-07-2003, 07:14 AM
What is the problem with my code?. how do I solve it right now?. I have only IE with me now. Any other alternative?.
glenngv
01-07-2003, 07:16 AM
Originally posted by kuchiv
No infact I am checking the check box. but no action performed. Can you go thru the code and then let me know what has gone wrong?. I am not able to make it.
ahh, I see it now! you use onchange instead of onclick.
<input type="checkbox" name="emergency" onchange=click1() value="emergency">
kuchiv
01-07-2003, 07:22 AM
Yes, I know, I have just changed as it was not working with onclick. Just to try it out. but nope, its not working even with this.
glenngv
01-07-2003, 07:31 AM
this should work.
<input type="checkbox" name="emergency" onclick="click1()" value="emergency"><BR>
<script>
function click1(){
alert('test')
}
</script>
what browser are you using?
Is Javascript enabled in your browser?
Originally posted by glenngv
It will work if the button had been like this:
<script>
click=2;
</script>
<input type="button" value="Watch me use click" onclick="alert(click); window.click = 1; alert(window.click);"/>
Obviously, but that was beside my entire point. You *should* be able to reassign "click" within the namespace of the input dom object. You *can* in Mozilla. You can't in IE.
kuchiv
01-07-2003, 08:52 AM
Did u go to the view source option in the browser and then look at the generated html code. I think its generating an error while executing this particular event. Dont u think so?
glenngv
01-07-2003, 08:59 AM
you didn't post a link to your page, did you?
how can I view the generated source?
and you didn't answer my 2 questions above.
kuchiv
01-07-2003, 09:29 AM
Well Glenn,
I am using IE 5.5 and yes, Javascript is enabled on it.
And regarding the error,
its not performing anything when I check the checkbox.
glenngv
01-07-2003, 09:41 AM
Well, if that's the case, then I don't know what's wrong with it. The function is just a simple alert and I don't see anything wrong with it. Is the code below the same as yours when the html has been generated by asp codes?
<input type="checkbox" name="emergency" onclick="click1()" value="emergency"><BR>
<script>
function click1(){
alert('test');
}
</script>
Also check that there is no duplicate declaration of the click1() function.
kuchiv
01-07-2003, 09:45 AM
Its not generating that. At the end of the html page, its saying that VBScript Error(some error number) and then its saying Object Required.
kuchiv
01-07-2003, 09:47 AM
The task is not to send an alert message. I am just trying out. But once when the checkbox is checked, then HTML page should show a textbox for input and if its not checked then couple of dropdown boxes will be displayed. I was just trying to see whether the onclick method works or not.
glenngv
01-07-2003, 10:00 AM
Yes, I understand that the alert is just a test.
So the error is not really on the javascript function! :eek:
It's in the VBscript code which is server-side. We have dwelled so much on the click1() function but you didn't mention at once that the error is in the vbscript code. :rolleyes:
So, this should be on the ASP forum.
What's on the line that has the Object required error?
kuchiv
01-08-2003, 02:12 AM
Well this particular block is not getting executed. And when we are going to the view source file, then it is showing the error at the end of the file.
glenngv
01-08-2003, 02:26 AM
It's a server-side error, isn't it? If it really is, then the mods should move this to ASP forum.
This thread keeps getting longer because you are not supplying the exact root of the problem. You are not answering my questions that will lead to the solution.
What's on the line that has the Object required error? The error says the line number, right? Go and look at your code to see what's on this line.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.