WebDatablade & Javascript: strange behaviour
Posted in 1997
Hi everybody: I just want to report a strange behaviour with the Webdatablade mixed with Javascript: If we have a portion of code like this: Webdatablade code mixed with Javascript: i.e. test if a given value exists and output as a table column, then test if it is a mail address. <?misql sql="Select *... <script language="Javascript"> ............................................... str_next_col = "$(NTH,2,$1,$2,$3,$4,$5,$6)"; if(str_next_col !="") { if(str_next_col.indexOf("@") != -1) { str_mailto = "<a href=mailto:" + str_next_col + ">" + str_next_col + "</a>"; str_selection = str_selection + "<td>" + str_mailto + "</td>"; } else str_selection = str_selection + "<td>" + str_next_col + "</td>"; } document.write(str_selection); </SCRIPT> <?/misql> The output expected should be(for each col. of the select statement, if a misql statement can be considered as a loop outputing columns: $1, $2,..., $n): if condition .... else .... if condition ... else ... Instead the output is of the form: all if's alltogether and else's as well. if the select statement outputs three cols. then 3 if's together and 3 else's together, therefore Javascript generates an error Alert. if condition .... if condition .... if condition .... else .... else .... else ... A portion of the output(view Netscape's document source): (6 cols in the select statement) str_next_col = "University of Sydney"; if(str_next_col !="") if(str_next_col.indexOf("@") != -1) if(str_next_col.indexOf("@") != -1) if(str_next_col.indexOf("@") != -1) if(str_next_col.indexOf("@") != -1) if(str_next_col.indexOf("@") != -1) if(str_next_col.indexOf("@") != -1) str_mailto = "<a href=mailto:" + str_next_col + ">" + str_next_col + "</a>"; str_selection = str_selection + "<td>" + str_mailto + "</td>"; else str_selection = str_selection + "<td>" + str_next_col + "</td>"; else str_selection = str_selection + "<td>" + str_next_col + "</td>"; else str_selection = str_selection + "<td>" + str_next_col + "</td>"; else str_selection = str_selection + "<td>" + str_next_col + "</td>"; else str_selection = str_selection + "<td>" + str_next_col + "</td>"; The funny thing is that it only happens with the if's and else's of the internal if where we test if it is a mail address. Did anybody noticed this strange behaviour? -- Carlos F. Enguix Decision Systems Laboratory Department of Business Systems The University of Wollongong Northfields Ave. Wollongong NSW 2522 E-mail: cfe01@wumpus.uow.edu.au Phone : (Aus) 02-42-214210 (Rest World) +61-42-214210 Fax : (Aus) 02-42-214474 (Rest World) +61-42-214474