473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

button linke value

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=2 3448&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

Jul 23 '05 #1
11 1405
On 15 Dec 2004 05:16:52 -0800, terti wrote:
<input name="btnPay" value="Continue with payment"
onclick="document.location='LoadPayment.asp?TPID=2 3448&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=2 3448&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"
Jul 23 '05 #2
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

Jul 23 '05 #3
On 15 Dec 2004 05:53:52 -0800, terti wrote:
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"
Jul 23 '05 #4
Ivo
"terti" wrote
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[i].type.toLowerCase()==='button'
&& a[i].onclick.indexOf('LoadPayment.asp')>0 ) {
a[i].click();
}
}

Are you sure this is within the law?
--
Ivo
Jul 23 '05 #5
Many thanks for the help
the .click() method gets the job done.

Regrds
T

Jul 23 '05 #6
On Wed, 15 Dec 2004 15:18:41 +0100, ZER0 wrote:
On 15 Dec 2004 05:53:52 -0800, terti wrote:
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)"
Jul 23 '05 #7
On Wed, 15 Dec 2004 15:31:57 +0100, Ivo wrote:
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)"
Jul 23 '05 #8
On Wed, 15 Dec 2004 15:55:56 +0100, ZER0 <ze********@libero.it> wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #9
On Wed, 15 Dec 2004 15:40:58 GMT, Michael Winter wrote:
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"
Jul 23 '05 #10
On Wed, 15 Dec 2004 16:50:24 +0100, ZER0 <ze********@libero.it> wrote:

[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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #11


terti wrote:
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=2 3448&rgid=7'"
type="button"><br> How can I extract the document.location portion from the html?
IOW. 'loadpayment.asp?tpid=23448&rgid=7'


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<script type="text/javascript">

function bclick(bname)
{
var i = 0,
el,
els,
f,
fs = document.forms;
while ((f = fs[i++]) && (els = f.elements))
if ((el = els[bname]) && null != el.onclick)
el.onclick();
}

setTimeout('bclick("btnPay")', 3000);

</script>
</head>
<body>
<form>
<input name="btnPay" value="Continue with payment"
onclick="document.location='loadpayment.asp?tpid=2 3448&rgid=7'"
type="button">
</form>
</body>
</html>

The button's name would suggest that it is in a (payment) form.

btw irrelevant but it's *window.location*; document.location has been
deprecated for years although all browsers appear to have mapped it to
window.location.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Per Steffensen | last post by:
Hi I have the following in my html: <input type="button" value="Short"/> <input type="button" value="Very long text on this button"/> It gives two buttons on the html form. My problem is...
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently...
11
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.