[miva] Very annoying (TM) Javascript/Miva interaction.

11 views
Skip to first unread message

Christopher Cookson

unread,
Apr 17, 2006, 6:27:41 AM4/17/06
to miva-...@googlegroups.com
Hi Folks,
hopefully there are some nice gurus out there who can resolve this one:

The following code is part of the output from a mivascript:

<td valign="center"><a href="javascript:WP_dialog('Alert','WARNING: Are you sure you
want to delete this style?', 1, '../images/exclaim_icn.gif',
'index.mvc?strTab=styles&amp;Action=d&amp;strDocID=%23leftmenu+li','Module');">Link1
</a></td>
<td valign="center"><a
href="index.mvc?strTab=styles&amp;func=edit&amp;Action=Modify&amp;strDocID=%23left
menu+li">Link2</a></td>

You will notice that both links are similar, but the first one calls a javascript function, while
the second one is just a standard link.
The second link works fine.
The first one however, doesn't work.
The javascript function called creates a popup window.

part of the code is as follows:

wnDialog.document.write('<form action="' + strAction + '" method="POST" id="dlg"
name="dlg" target="'+ strTarget+ '"></form>');

where strAction is the URL passed from the javascript URL above.

Unfortunately when this is output by javascript, any url encoded characters are output as
their character equivalents rather than retaining their url encoding, ie %23 ends up as #
so a line as follows is produced.

<form action="index.mvc?strTab=styles&Action=d&strDocID=#+content+a"
method="POST" id="dlg" name="dlg" target="Module">

When this is sent back to Miva, if I do:

<MvEVAL EXPR="{g.strDocID}">

I get a great big null.

I have confirmed that this is because of the non-encoded # since if strDocID is a plain text
string everything functions as I would expect.

I have also confirmed that strDocID has a non null value and behaves as expected in the
second URL in the example.

Just using the javascript escape() function to escape the whole string doesn't fix things.

Anyone with any bright ideas on how to get Javascript and Mivascript to be nice playmates
in this situation?

--
Christopher Cookson
Create IT, 4 Safe St, Blenheim
ph +64 3 578 1721 mobile +64 274 969 735
http://www.createit.co.nz

bi...@billbuilt.com

unread,
Apr 17, 2006, 4:19:53 PM4/17/06
to miva-...@googlegroups.com
Christopher,

Just taking a stab here but the # character in a url typically refers to an
anchor. Maybe it's getting confused on that. Can you use another character?
Or, use another character as a placeholder then using the javascript
equivalent to glosub() to put the # back? Maybe if you posted the WP_dialog
function I could help better.

Another thing I noticed:
>> 'index.mvc?strTab=styles&amp;Action=d&amp;strDocID=%23leftmenu+li'
(there's no + between %23 and leftmenu)


>> <form action="index.mvc?strTab=styles&Action=d&strDocID=#+content+a"
method="POST" id="dlg" name="dlg" target="Module">

(there's a + between # and content)

In the above example, is strDocID supposed to equal "#+content+a" so that it
actually equals "# content a" ?

I'm guessing that strDocID is not getting set because the browser is
interpreting #+content+a to be an anchor named " content a", which doesn't
exist.

You could also try entity encoding the attribute encoded url.... Something
like encodeentities(encodeattribute('# content a'))

HTH,
Bill M.

Christopher Cookson

unread,
Apr 18, 2006, 12:43:33 AM4/18/06
to miva-...@googlegroups.com
Hi Bill,
I resolved things in the end using a mixture of glosub in miva, and the replace() method
in Javascript. replace is very cool as it supports regular expressions.

What's happening is I'm reading stuff from a database of CSS styles. Obviously # is
important (as is .) to define CSS class and ID selectors.

I can happily delete my CSS ID selectors now! I've just got to warn in my
documentation not to start any CSS definition with an underscore, as that's what I've
used as a substitute.


>
> Christopher,
>
> Just taking a stab here but the # character in a url typically refers to an
> anchor. Maybe it's getting confused on that. Can you use another character?
> Or, use another character as a placeholder then using the javascript
> equivalent to glosub() to put the # back? Maybe if you posted the WP_dialog
> function I could help better.

The idea of the function is to provide a confirmation dialog before deleting a record, but
without having to go back to the server just to show a dialog, and also to allow code
reuse so that I can use the same dialog regardless of what screen I'm working with.
(sort of almost like a predecessor to AJAX I've just realised, and I've used this function
for several years!)

>
> Another thing I noticed:
> >> 'index.mvc?strTab=styles&amp;Action=d&amp;strDocID=%23leftmenu+li'
> (there's no + between %23 and leftmenu)
> >> <form action="index.mvc?strTab=styles&Action=d&strDocID=#+content+a"
> method="POST" id="dlg" name="dlg" target="Module">
> (there's a + between # and content)
>
> In the above example, is strDocID supposed to equal "#+content+a" so that it
> actually equals "# content a" ?

Yes that is correct.

>
> I'm guessing that strDocID is not getting set because the browser is
> interpreting #+content+a to be an anchor named " content a", which doesn't
> exist.
>
> You could also try entity encoding the attribute encoded url.... Something
> like encodeentities(encodeattribute('# content a'))

Tried that, but the Javascript function keeps decoding everything before it sends it to
the browser, and that causes the problem.

Reply all
Reply to author
Forward
0 new messages