Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP OnClick Jscript problems (Sending variables through Function call) 1

Status
Not open for further replies.

Zycmi

IS-IT--Management
Jun 19, 2002
42
CA
Hi, I was wondering if anyone could help me find the problem in my code. I've managed to find a good JScript Date picker calendar, where a user clicks a button to make the calendar appear, then cooses a date and it is then entered in the textbox beside it.
This all works fine provided I use a specific name for the textbox. But, I want to use a variable for the textbox name.
The Command Button calls a JScript line, then opens a .JS file, now, HOW do I send an ASP variable to be read in the JS file. Here is the code for the textbox and cmdbutton.

*The syntax for code does not work.
<------------------Code Follows------------------->

<INPUT type=text name=&quot;<%=strAddress%>&quot; value='<%=Month(Date()) & &quot;/&quot; & Day(Date()) & &quot;/&quot; & Year(Date())%>' onchange=&quot;Jscript:cbfloadmefirst('Details_info', strAddress);&quot;>

<INPUT id=btn2 type=button value='Calendar' onclick=&quot;Jscript:cbfshowcalendar('Details_info', strAddress, 'btn2');event.cancelBubble=true;&quot;>

<------------------End Code ---------------------->
The variable I wish to use is strAddress as seen above.
In the OnChange and onClick events, the first called parameter is the Form name, the second is the form object name.
In those three areas, if I enter a string, such as &quot;joe&quot;
the code works. however, the code is inside a loop, therefore, I need a variable name for the textbox name.
What would be the proper syntax or procedure to get this code to work.

I would like to thank you in advance for your assistance and co-operation.

Zycmi
 
You need to use the same principal you've used for setting the textbox name ie Response.Write the variable value to the page:

Code:
onchange=&quot;Jscript:cbfloadmefirst('Details_info', <%=strAddress%>);&quot;>

onclick=&quot;Jscript:cbfshowcalendar('Details_info', <%=strAddress%>, 'btn2');
--James
 
I have tried the suggested modifications, and the following JScript error appears:

Error: Expected ';'
Code: 0

The calendar won't show either.
 
if you've declared jscript as the language type in the page then all lines must be followed with the ;
<%=strAddress;%>

I'm also not sure the short cut = is available in jscript but I just never tried it when I used jscript as a langauge in ASP. _________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Hi, I've tried placing a ; at the end of my response.write, then it sais:

Expected end of statement

/test/projectDetails.asp, line 78

response.write strAddress;
-------------------------^

My page is primarily built using VBScript, and my JScript declaration looks like this:


<SCRIPT language=Jscript src=calendar.js></SCRIPT>
<SCRIPT FOR=document EVENT=&quot;onclick()&quot;>document.all.CalFrame.style.display=&quot;none&quot;;</SCRIPT>

 
my apologies, when I saw jscript mentioned I was under the impression that was being used server side.

undue my mistakes in reading the thread please.

one note: the jscript does not go in the onCLick event. as jscript:

it needs to
onclick=&quot;cbfshowcalendar('Details_info', <%=strAddress%>, 'btn2'); _________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
by removing the jsript: the same situation resulted.

Error: Expected ';'
Code: 0

Strange. seems like so much trouble just to send a vbscript variable to a .js file.
problem is, my site will not work otherwise.

Most of the code was copied from a Sample code offered at:

 
what data type is strAddress?
if the data type is not a integer then you need to enclose the value in quotes.
onclick=&quot;cbfshowcalendar('Details_info', '<%=strAddress%>', 'btn2');

you can also see more examples of this faq333-3048
which can be a bedug tool along with a few other FAQ for your type of error. _________________________________________________________
for the best results to your questions: FAQ333-2924
01001111 01101110 01110000 01101110 01110100
onpnt2.gif
[/sub]
 
Same situation.

Error: Expected ';'
Code: 0

------------------------------------

I've also tried casting it to a string just in case, though the variable IS a number turned string.
(basically joined two 2 digit numbers

also, if it makes a difference, the server is an NT server indicative of the use of ASP 2.0
 
OK, I just wanted to thank everyone for their prompt help.
I just noticed that Jscript variables don't accept a number to be the first character. by adding an underscore, it worked. Thank you very much.

It still won't work if repeated more than a single time, but I'm one step closer for sure.
Thanks a bunch.

Zycmi

Any suggestions on the repeated code error?
When the call is repeated on a single page. clicking on the button (either the first one, or the second) produces the following error.

Error: Invalid Argument
Code: 0

Any insight? thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top