Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Langages serveur > ASP
ASP Forum sur la programmation ASP. Avant de poster : Cours ASP, FAQ ASP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 27/07/2006, 10h49   #1
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
Par défaut ASP et fonction javascript

Bonjour,
je souhaiterais insérer une fonction javascript dans une partie de code ASP. Il s'agit d'une fonction que je souhaiterais faire fonctionner lors du click sur le lien.
le code asp est le suivant:
Listoffilesfound= Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD ALIGN=CENTER VALIGN=MIDDLE> <A HREF= " & Thefilep & " > View </A></TD><TD ALIGN=right VALIGN=MIDDLE><A target='_blank' HREF=" & Thefilep & " > View in a new window</A></td></TR>"
je souhaiterais donc inserer ma fonction cacher() soit avec le href cacher(Thefilep), soit cacher() avec un onclick (la fonction marche avec et sans arguments). Le probleme est que je dois avoir des erreurs de "" car cela ne marche pas.
Listoffilesfound= Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD ALIGN=CENTER VALIGN=MIDDLE> <A HREF= " & Thefilep & " onclick='cacher()'> View </A></TD><TD ALIGN=right VALIGN=MIDDLE><A target='_blank' HREF=" & Thefilep & " > View in a new window</A></td></TR>"
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h14   #2
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
essaie en mettant onclick=""cacher()""
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h33   #3
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
pas d erreur signalée, mais cela ne marche pas. la fonction ne s'exécute pas
aurais tu une autre idée?
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h38   #4
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
Il affiche ton lien correctement? tu le fais a quel moment dans ton code ton appel?
tu es sur de ton code html?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h45   #5
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
il affiche le lien sans problemes mais sans jouer le onclick.
j'appelle ma fonction dans un tableau html de la facon suivante
<TABLE BORDER=0 WIDTH=600>

<% if Listoffilesfound="" then %>
<TR><TD>The specified term or phrase was not found</TD></TR>
<% else
Response.Write (Listoffilesfound)
end if %>

</TABLE>

je desespere et pourtant je pense que ce n'est qu une erreur de guillemets ou un detail
Help
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h52   #6
Membre éprouvé
 
Inscription : septembre 2004
Messages : 368
Détails du profil
Informations forums :
Inscription : septembre 2004
Messages : 368
Points : 402
Points : 402
Salut,

as tu essayé :

Code :
<A HREF= " & Thefilep & " onclick="" 'cacher()' "">
deux doubles quotes avant la simple quote et deux apres. J'ai volontairement ajouté un espace pour la lisibilité.
Gwenn est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 11h52   #7
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
et avec:
Code :
Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD ALIGN=""CENTER"" VALIGN=""MIDDLE""> <A HREF=" & Thefilep & " onclick=""cacher()""> View </A></TD><TD ALIGN=""right"" VALIGN=""MIDDLE""><A target=""_blank"" HREF=" & Thefilep & " > View in a new window</A></td></TR>"
?

"" ' cacher()' "" ne devrait pas marccher gwenn, vu que ce n'est pas un script javascript à ce moment mais un appel html. Je me trompe?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h01   #8
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
merci pour vos reponses.
la solution de gwenn n execute pas la fonction.
et avec ta solution bossgana, la page ne s'affiche meme plus.
merci j espere vraiment qu on va y ariver car c la seule chose qu il me manque pour boulcer un projet de trois moi...
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h23   #9
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
huh? Chez moi ca s'affiche...j'ai un tableau, 3 cellules. Dans la premiere, le titre, dans la deuxieme un lien appelé view avec cacher(qui est détecté), et une troisieme cellule avec un lien qui ouvre dans une nouvelle page.
Tu es sous quel navigateur?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h29   #10
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/AS400Asp/Zsearch.asp, line 246, column 17

voici l erreur, la ligne 246 etant biensur celle que l on cherche á ecrire
Pour ce qui est du navigateur, j'utilise IE...
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h35   #11
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
comme cela le code passe, tout s affiche mais la fonction n est pas joué....

Listoffilesfound=Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD
ALIGN=""CENTER"" VALIGN=""MIDDLE""> <A HREF=" & Thefilep & " onclick=""cacher()""> View </A></TD><TD ALIGN=""right"" VALIGN=""MIDDLE""><A target=""_blank"" HREF=" & Thefilep & " > View in a new window</A></td></TR>"
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h47   #12
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
remontre ton tableau tel qu'il est actuellement.
tu mets quoi comme chaine dans Listoffilesfound ?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h52   #13
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
bon je vais copier tout le code meme s'il est long.
Le principe de la fonction est une fonction de recherche style google qui va chercher dans les title des pages. Le principe est que la box pour rentrer le mot á chercher est dans une iframe elle meme dans une frame. Et j affiche la résultat dans une autre frame.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<%@ Language=VBScript %>
<% 
DIM Listoffilesfound,Thefile,Thefolder,Folderpath,FileSystemObject
Set FileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
 
if request.form="" then
   SendForm()
else
SearchTerm = Server.HTMLencode(request.form("term"))
if Searchterm<>"" then
SearchTermArray=Split(SearchTerm," ")
MaxSearchTerms=ubound(SearchTermArray)
 
Folderstosearch="\menus_new\newmenu"
Folderstosearchasp="\..\as400asp"
Folderstosearchp="\..\pageintranet"
 
 
DonotsearchthisFiles =""
 
 
 
Folderpath=server.mappath("\")
' Search folders
If (FileSystemObject.FolderExists(Folderpath & Folderstosearch) = true) Then
FolderstosearchArray=Split(Folderstosearch,",")
Maxfolders=ubound(FolderstosearchArray)
for i=0 to Maxfolders
		Thefolder = FolderstosearchArray(i)
     Dim fs, f, f1, fc, s 
        Set fs = CreateObject("Scripting.FileSystemObject") 
 
        Set f = fs.GetFolder(Folderpath & Thefolder) 
        Set fc = f.Files 
        For Each f1 in fc
             Wfile = f1.name 
						 Thefile=Thefolder & "/" & Wfile
             if (inStr(DonotsearchthisFiles,Thefile)=0 and (inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"htm")or inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"asp") or inStr(mid(Wfile,len(Wfile)-4,len(Wfile)),"html"))) then
 
                		Searchit()
             end if 
                    Next 
next
end if
 
If (FileSystemObject.FolderExists(Folderpath & Folderstosearchasp) = true) Then
             FolderstosearchArrayasp=Split(Folderstosearchasp,",")
Maxfoldersasp=ubound(FolderstosearchArrayasp)
for k=0 to Maxfoldersasp
		Thefolderasp = FolderstosearchArrayasp(k)
     Dim fsasp, fasp, f1asp, fcasp, sasp 
        Set fsasp = CreateObject("Scripting.FileSystemObject") 
 
        Set fasp = fsasp.GetFolder(Folderpath & Thefolderasp) 
        Set fcasp = fasp.Files 
        For Each f1asp in fcasp 
             Wfile = f1asp.name 
						 Thefileasp=Thefolderasp & "/" & Wfile
             if (inStr(DonotsearchthisFiles,Thefileasp)=0 and (inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"htm")or inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"asp") or inStr(mid(Wfile,len(Wfile)-4,len(Wfile)),"html"))) then
              if inStr(Thefileasp,"Zsearch")= 0 then
                		Searchitasp()
                		end if
             end if 
 
       Next 
next
end if
 
 
 
	If (FileSystemObject.FolderExists(Folderpath & Folderstosearchp) = true) Then	
     Dim fsp, fp, f1p, fcp, sp 
        Set fsp = CreateObject("Scripting.FileSystemObject")
        Set fp = fsp.GetFolder(Folderpath) 
        Set fcp = fp.Files 
        For Each f1p in fcp 
             Wfile = f1p.name 
						 Thefilep=Folderstosearchp & "/" & Wfile
             if (inStr(DonotsearchthisFiles,Thefilep)=0 and (inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"htm")or inStr(mid(Wfile,len(Wfile)-3,len(Wfile)),"asp") or inStr(mid(Wfile,len(Wfile)-4,len(Wfile)),"html"))) then
                		 if inStr(Thefilep,"Zsearch")= 0 then
                		Searchitp()
                		end if
             end if 
 
       Next 
end if
 
' Write search results
Searchresponse()
end if
 
end if
 %><% Sub SendForm() %>
 
<HTML>
<HEAD>
<script>
function cacher() {
	//self.parent.parent.parent.parent.parent.document.body.rows="0,*";
	alert ('ouais');
	//window.top.document.body.rows ="0,*";	
 
	top.document.body.rows ="0,*";
 
	}
 
	function cacherurl(url) {
 
	top.document.body.rows ="0,*";
	self.location.href=url;
 
}
 
function onenter(){
	if(event.keyCode==13){
	cacher();
	}
} 
</script>
 
<TITLE>Search</TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF ><CENTER>
<form method="POST" action="Zsearch.asp" target="Cright" > 
 <table border=0 cellpadding=0 cellspacing=0 ><tr> 
 <td align=center> 
 <!--Enter term to search &nbsp;-->
 <input type=text name=term value="search menus" size=14 onkeypress="Javascript:onenter();">
 <input name=submit type=image SRC="iseek.gif" ALT="search" value="search" onclick="javascript:cacher();">
 </td> 
 </tr>
  <tr >
 <IMG SRC="searchmac.jpg">
 </tr>
 </table> 
 </form>
 
 
</CENTER></BODY></HTML>
<% End Sub %>
<% Sub Searchresponse() %>
<HTML>
<HEAD>
<TITLE>Search results</TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFF ><CENTER> 
 
<TABLE BORDER=0 WIDTH=600><TR><TD BGCOLOR=C0C0C0><FONT SIZE=5><B>Search Results</B></FONT></TD></TR></TABLE>  
 
<TABLE BORDER=0 WIDTH=600>
 
  <% if Listoffilesfound="" then %>
    <TR><TD>The specified term or phrase was not found</TD></TR> 
  <% else 
    Response.Write (Listoffilesfound)  
  end if %>
 
</TABLE> 
 
<TABLE BORDER=0 WIDTH=600><TR><TD BGCOLOR=C0C0C0 ALIGN=RIGHT><FONT SIZE=1>Search utility provided by Page Aerospace</A></FONT></TD></TR></TABLE> 
 
</CENTER></BODY></HTML> 
 
<% End Sub %>
 
<% Sub Searchit() 
if inStr(Thefile,"Zsearch.asp")=false then
Thefilepath=Folderpath & Thefile
Set fs = CreateObject("Scripting.FileSystemObject") 
Set a = fs.OpenTextFile(Thefilepath) 
ThecontentofFile = a.ReadAll 
a.close 
'ThecontentofFile=notag(ThecontentofFile)
 
Findterms=0
for j=0 to MaxSearchTerms
   if instr(1,ThecontentofFile,"</title>",1)>0 and instr(1,ThecontentofFile,"<title>",1)>0 then  
      TheTitle=left(ThecontentofFile,instr(1,ThecontentofFile,"</title>",1)-1)      
      TheTitle=right(TheTitle,len(TheTitle)-instr(1,TheTitle,"<title>",1)-6) 
   end if
 if instr(1,Thetitle,SearchTermArray(j),1)>0 then 
		Findterms=Findterms+1
 end if
next
 
if Findterms=MaxSearchTerms+1 then 
 
 
'Listoffilesfound= Listoffilesfound & "<TR><TD>" & TheTitle  & "</TD><TD ALIGN=CENTER VALIGN=MIDDLE> <A HREF= " & Thefile & " onClick=\'cacher()\' > View </A></TD><TD ALIGN=right VALIGN=MIDDLE><A target='_blank' HREF=" & Thefile & " > View in a new window</A></td></TR>" 
 
end if
end if
 
 End Sub %>
 
 <% Sub Searchitasp() 
 if inStr(Thefileasp,"Zsearch")= 0 then
Thefilepath=Folderpath & Thefileasp
Set fs = CreateObject("Scripting.FileSystemObject") 
Set a = fs.OpenTextFile(Thefilepath) 
ThecontentofFile = a.ReadAll 
a.close 
'ThecontentofFile=notag(ThecontentofFile)
 
Findterms=0
for j=0 to MaxSearchTerms
   if instr(1,ThecontentofFile,"</title>",1)>0 and instr(1,ThecontentofFile,"<title>",1)>0 then  
      TheTitle=left(ThecontentofFile,instr(1,ThecontentofFile,"</title>",1)-1)      
      TheTitle=right(TheTitle,len(TheTitle)-instr(1,TheTitle,"<title>",1)-6) 
   end if
 if instr(1,Thetitle,SearchTermArray(j),1)>0 then 
		Findterms=Findterms+1
 end if
next
 
if Findterms=MaxSearchTerms+1 then 
 
 
Listoffilesfound= Listoffilesfound & "<TR><TD>" & TheTitle  & "</TD><TD ALIGN=CENTER VALIGN=MIDDLE> <A  HREF=" & Thefileasp & " > View </A></TD><TD ALIGN=right VALIGN=MIDDLE><A target='_blank' HREF=" & Thefileasp & " > View in a new window</A></td></TR>" 
end if
end if
 
 End Sub %>
 
  <% Sub Searchitp() 
Thefilepath=Folderpath & Thefilep
Set fs = CreateObject("Scripting.FileSystemObject") 
Set a = fs.OpenTextFile(Thefilepath) 
ThecontentofFile = a.ReadAll 
a.close 
'ThecontentofFile=notag(ThecontentofFile)
 
Findterms=0
for j=0 to MaxSearchTerms
   if instr(1,ThecontentofFile,"</title>",1)>0 and instr(1,ThecontentofFile,"<title>",1)>0 then  
      TheTitle=left(ThecontentofFile,instr(1,ThecontentofFile,"</title>",1)-1)      
      TheTitle=right(TheTitle,len(TheTitle)-instr(1,TheTitle,"<title>",1)-6) 
   end if
 if instr(1,Thetitle,SearchTermArray(j),1)>0 then 
		Findterms=Findterms+1
 end if
next
 
if Findterms=MaxSearchTerms+1 then 
 
Listoffilesfound=Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD ALIGN=""CENTER"" VALIGN=""MIDDLE""> <A HREF=" & Thefilep & " onclick=""cacher()""> View </A></TD><TD ALIGN=""right"" VALIGN=""MIDDLE""><A target=""_blank"" HREF=" & Thefilep & " > View in a new window</A></td></TR>"
'Listoffilesfound= Listoffilesfound & "<TR><TD>" & TheTitle  & "</TD><TD ALIGN=CENTER VALIGN=MIDDLE> <A HREF=" & Thefileasp & "  > View </A></TD><TD ALIGN=right VALIGN=MIDDLE><A target='_blank' HREF=" & Thefilep & " > View in a new window</A></td></TR>" 
 
 
end if
 
 End Sub %>
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h55   #14
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
argh utilise la balise code
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h57   #15
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
voila j ai modifié le mesage en utilisant la balise
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 12h59   #16
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
c'est pas mais C'est pas la que tu as une erreur?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 13h05   #17
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
dsl
j'ai du te copier le code quand je faisais une tentative desespérée...
sinon j'ai bien mis ce que tu m'as dit:
Code :
1
2
3
4
 
 
 
Listoffilesfound=Listoffilesfound & "<TR><TD>" & TheTitle & "</TD><TD ALIGN=""CENTER"" VALIGN=""MIDDLE""> <A HREF=" & Thefilep & " onclick=""cacher()""> View </A></TD><TD ALIGN=""right"" VALIGN=""MIDDLE""><A target=""_blank"" HREF=" & Thefilep & " > View in a new window</A></td></TR>"
Pas d erreur, mais le onclick ne se joue pas.
peut etre est il possible de faire quelque chose avec href=javacript:cacherurl(" & Thefilep & ");
j'ai essayé ca n'a rien donné mais j'espere y ariver á force
merci de continuer á m'aider
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 13h10   #18
Membre actif
 
Inscription : juin 2006
Messages : 431
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 431
Points : 162
Points : 162
et un response.write de Listoffilesfound tout seul donne quoi?
boss_gama est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 13h30   #19
HiT
Débutant
 
Inscription : juillet 2004
Messages : 74
Détails du profil
Informations forums :
Inscription : juillet 2004
Messages : 74
Points : 4
Points : 4
qu entends tu par tout seul?
HiT est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 27/07/2006, 13h45   #20
Membre éprouvé
 
Inscription : septembre 2004
Messages : 368
Détails du profil
Informations forums :
Inscription : septembre 2004
Messages : 368
Points : 402
Points : 402
Quand j'ai ce soucis, j'y vas par tatonnement Si jamais ca peut t'aider :

j'ia un bout de code javascript dans une chaine asp :

Code :
Response.write "<img src="& sDirImage & "/" & p & " onClick=document.getElementById(""img_art"").src=""" & sImage & """;document.getElementById(""img_hi"").value=""" & sImage & """ />"
Gwenn est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h08.


 
 
 
 
Partenaires

Hébergement Web