button linke value

T

terti

Hi there, newbie here.

appologies if this is OT. (DOM based)

I have a button defined in the html as follows:

<input name="btnPay" value="Continue with payment"
onclick="document.location='LoadPayment.asp?TPID=23448&RGID=7'"
type="button"><br>

How can I extract the document.location portion from the html?
IOW. 'LoadPayment.asp?TPID=23448&RGID=7'

Many TIA
T
 
Z

ZER0

<input name="btnPay" value="Continue with payment"
onclick="document.location='LoadPayment.asp?TPID=23448&RGID=7'"
type="button"><br>
How can I extract the document.location portion from the html?
IOW. 'LoadPayment.asp?TPID=23448&RGID=7'

I don't know why you need to do it, it's a bit "ugly".. BTW, a method could
be:

<input id="btn-pay" name="btnPay" value="Continue with payment"
onclick="document.location='LoadPayment.asp?TPID=23448&RGID=7'"
type="button">

<script type="text/javascript">
function getPayURI(){
var btn=document.getElementById("btn-pay"),
txt=btn.getAttribute("onclick"),
res=[];

txt=typeof txt=="function"?txt.toString():txt;

res=txt.match(/document\.location='([^']+)'/);

return (res && res[1])?res[1]:null;
}

alert(getPayURI())
</script>

--
ZER0

~ The Tangent Universe collapsed 5890 days, 8 hours, 30 minutes and 35 seconds ago.

on air ~ "The Church - Under The Milky Way Tonight"
 
T

terti

Thanks for the reply,

I can not alter the html that is sent to me so the getElementById() may
not work
What I really wanty to do is to simmilate a button being pressed
without user intervention.


The reason why I wanted the link was so that I could follow it with a
get() method.
Is there a way to simmulate a butted pressed event ?

thanks
T
 
Z

ZER0

Thanks for the reply,

I can not alter the html that is sent to me so the getElementById() may
not work

This is not a problem, you can use getElementsByTagName instead:

var btn=document.getElementsByTagName("btnPay")[0]
What I really wanty to do is to simmilate a button being pressed
without user intervention.

You can try with click() method, then.

document.getElementsByTagName("btnPay")[0].click();

--
ZER0

~ The Tangent Universe collapsed 5890 days, 9 hours, 18 minutes and 41 seconds ago.

on air ~ "Donnie Darko - Cellar Door"
 
I

Ivo

Thanks for the reply,

I can not alter the html that is sent to me so the getElementById() may
not work
What I really wanty to do is to simmilate a button being pressed
without user intervention.

You don't need getElementById(). The following code will loop through all
input's on the page (in reverse order btw, that 's usually faster this way)
and activite the first it finds that points to said url:

var a=document.getElementsByTagName('input');
var i=a.length; while(i--) {
if( a.type.toLowerCase()==='button'
&& a.onclick.indexOf('LoadPayment.asp')>0 ) {
a.click();
}
}

Are you sure this is within the law?
 
Z

ZER0

Thanks for the reply,

I can not alter the html that is sent to me so the getElementById() may
not work

This is not a problem, you can use getElementsByTagName instead:

var btn=document.getElementsByTagName("btnPay")[0]

Argh, sorry.. I was misunderstanding:

var btn=document.getElementsNames("btnPay")[0]

--
ZER0

~ The Tangent Universe collapsed 5890 days, 9 hours, 53 minutes and 20 seconds ago.

on air ~ "donny darko - Mad World (full version)"
 
Z

ZER0

You don't need getElementById(). The following code will loop through all
input's on the page (in reverse order btw, that 's usually faster this way)

You can use document.getElementsNames("btnPay")[0] for obtain the reference
to button.. The loop is not necessary:

document.getElementsNames("btnPay")[0].click()

--
ZER0

~ The Tangent Universe collapsed 5890 days, 9 hours, 55 minutes and 56 seconds ago.

on air ~ "donny darko - Mad World (full version)"
 
M

Michael Winter

[snip]
You can use document.getElementsNames("btnPay")[0]

The name is getElementsByName, but considering that this control is in a
form,

document.forms[...].elements['btnPay']

where the ellipsis is either a number or a string containing the name or
id of the form, would be better.

[snip]

Mike
 
Z

ZER0

You can use document.getElementsNames("btnPay")[0]
The name is getElementsByName,

yes, I misunderstanding again.. unfortunately, I've made a copy&paste in
my post.. :) but the concept is the same.
but considering that this control is in a form,

well, I don't know if the control is in a form. In the post of terti the
code is out of context.
So, I wrote a code that works with or without a form parent element.
document.forms[...].elements['btnPay']

In that case you can use directly:

document.forms[...].btnPay.click();

or

document.forms.nameOfForm.btnPay.click();

as well.

P.S.
Sorry for my english, I know is not very good.

--
ZER0

~ The Tangent Universe collapsed 5890 days, 10 hours, 50 minutes and 24 seconds ago.

on air ~ "Tears For Fears - Head Over Heels"
 
M

Michael Winter

[snip]
well, I don't know if the control is in a form.

Re-examining the original post, it might not be. The text of the button,
"Continue with payment", would suggest that it is a submit button, but
it's not.

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top