Help with mechanize and javascript

------=_Part_111961_16924063.1182457415686
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello all, this is my first post to this list. I am fairly new to
WWW::Mechanize, but I have been in pretty good shape so far. I have run
into a page that has a javascript link to another page and I can't get by
it. I am trying to use push_input to get by that way, but I can't seem to
translate the javascript to see what I should configure. Below is the
javascript snippet. Any help is appreciated.

Thanks.

~Paul

<script language="JavaScript" type="text/javascript">
function setAndSubmit(actionName, formObj, varNameAndValueArray)
{
for(var i = 0; i < varNameAndValueArray.length; ++i)
{
eval("document."+formObj.name+"."+varNameAndValueArray[i]+". value=\""+varNameAndValueArray[++i]+"\";");
}

//if NN4
if(document.layers)
{
var whichDummy;
//if there is more than one form variable named dummy
//find the first one that hasn't been renamed and use it
if( formObj.dummy.length != null )
{
var done = false;
for(i=0; i < formObj.dummy.length && !done; ++i)
{
if( formObj.dummy[i].name == "dummy" )
{
whichDummy = i;
done = true;
}
}
if( !done )
{
alert("Error: All dummy variables used up!");
}

eval("document."+formObj.name+".dummy[whichDummy].name=\""+a ctionName+".x\"");
}
//if there is only one dummy field, just use it
else
{

eval("document."+formObj.name+".dummy.name=\""+actionName+". x\"");
}
formObj.submit();
}
}
</script>


Above is the function that gets passed the variables, here is the
snippet that calls the function.


<input type=hidden name=GroupId value="">
<td valign=top>
<!-- ugly script to write out image link for netscape or image button for IE-->
<script language="JavaScript" type="text/javascript">
//if NN4
if(document.layers)
{
document.write("<input type=\"hidden\" name=\"dummy\" value=\"1\" />");
document.write("<a
href=\"javascript:setAndSubmit('EDIT_STORE_RULES_GROUP',
document.updateAccount, ['GroupId', '524789']);\"><img
src=\"/nhin/jsp/images/editstorehours.gif\"
alt=\"EDIT_STORE_RULES_GROUP\" border=\"0\" /></a>");
}
else
{
document.write("<input type=image
src=\"/nhin/jsp/images/editstorehours.gif\"
name=\"EDIT_STORE_RULES_GROUP\"
onclick=\"javascript:setAndSubmit('EDIT_STORE_RULES_GROUP',
document.updateAccount, ['GroupId', '524789']);\"
alt=\"EDIT_STORE_RULES_GROUP\" />");
}
</script>

</td>

------=_Part_111961_16924063.1182457415686--
robbins.paul [ Do, 21 Juni 2007 22:23 ] [ ID #1745375 ]

RE: Help with mechanize and javascript

Have you tried sniffing your browser's HTTP requests to see what happens
when that JS executes? Firefox has a nice plugin called Tamper Data
that does this.

-----Original Message-----
From: Paul Robbins [mailto:robbins.paul [at] gmail.com]
Sent: Thursday, June 21, 2007 4:24 PM
To: libwww [at] perl.org
Subject: Help with mechanize and javascript

Hello all, this is my first post to this list. I am fairly new to
WWW::Mechanize, but I have been in pretty good shape so far. I have run
into a page that has a javascript link to another page and I can't get
by it. I am trying to use push_input to get by that way, but I can't
seem to translate the javascript to see what I should configure. Below
is the javascript snippet. Any help is appreciated.

Thanks.

~Paul

<script language=3D"JavaScript" type=3D"text/javascript">
function setAndSubmit(actionName, formObj, varNameAndValueArray)
{
for(var i =3D 0; i < varNameAndValueArray.length; ++i)
{

eval("document."+formObj.name+"."+varNameAndValueArray[i]+". value=3D\""+v=
a
rNameAndValueArray[++i]+"\";");
}

//if NN4
if(document.layers)
{
var whichDummy;
//if there is more than one form variable named dummy
//find the first one that hasn't been renamed and use it
if( formObj.dummy.length !=3D null )
{
var done =3D false;
for(i=3D0; i < formObj.dummy.length && !done; ++i)
{
if( formObj.dummy[i].name =3D=3D "dummy" )
{
whichDummy =3D i;
done =3D true;
}
}
if( !done )
{
alert("Error: All dummy variables used up!");
}

eval("document."+formObj.name+".dummy[whichDummy].name=3D\"" +actionName+"=
..
x\"");
}
//if there is only one dummy field, just use it
else
{

eval("document."+formObj.name+".dummy.name=3D\""+actionName+ ".x\"");
}
formObj.submit();
}
}
</script>


Above is the function that gets passed the variables, here is the
snippet that calls the function.


<input type=3Dhidden name=3DGroupId value=3D""> <td valign=3Dtop>
<!-- ugly script to write out image link for netscape or image button
for IE--> <script language=3D"JavaScript" type=3D"text/javascript">
//if NN4
if(document.layers)
{
document.write("<input type=3D\"hidden\" name=3D\"dummy\"
value=3D\"1\" />");
document.write("<a
href=3D\"javascript:setAndSubmit('EDIT_STORE_RULES_GROUP',
document.updateAccount, ['GroupId', '524789']);\"><img
src=3D\"/nhin/jsp/images/editstorehours.gif\"
alt=3D\"EDIT_STORE_RULES_GROUP\" border=3D\"0\" /></a>");
}
else
{
document.write("<input type=3Dimage
src=3D\"/nhin/jsp/images/editstorehours.gif\"
name=3D\"EDIT_STORE_RULES_GROUP\"
onclick=3D\"javascript:setAndSubmit('EDIT_STORE_RULES_GROUP' ,
document.updateAccount, ['GroupId', '524789']);\"
alt=3D\"EDIT_STORE_RULES_GROUP\" />");
}
</script>

</td>
ted.behling [ Do, 21 Juni 2007 23:22 ] [ ID #1745376 ]
Perl » perl.libwww » Help with mechanize and javascript

Vorheriges Thema: www::Mechanize - problems finding forms
Nächstes Thema: WWW::Mechanize -- bug in find_all_images