Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Link acting as a submit button

5 views
Skip to first unread message

Matt Palermo

unread,
Jul 24, 2003, 6:35:56 PM7/24/03
to php-g...@lists.php.net
I am trying to create a submit button out of a hyperlink using the
following
code:

(this is in a file called index.html)
<A href="javascript:go_where_my_variable_says('this.php');">this
page</a>


<SCRIPT LANGUAGE="JavaScript">
<!--
function go_where_my_variable_says(where)
{
document.forms[0].action = where;
document.forms[0].submit();
}
//-->
</SCRIPT>

This works fine as an html document, however, when I try to echo the
same code
out in a PHP page, it gives me javascript errors. I am using the
following to
echo it out in PHP:

echo "
<A href=\"javascript:go_where_my_variable_says('this.php');\">this
page</a>


<SCRIPT LANGUAGE=\"JavaScript\">
<!--
function go_where_my_variable_says(where)
{
document.forms[0].action = where;
document.forms[0].submit();
}
//-->
</SCRIPT>
";

This displays the link fine for the submit hyperlink, but it gives the
javascript error:

Error: Object doesn't support this property or method.
Code: 0

Like I said before, this code works perfectly fine if I have it an html
document.

Anyone got any ideas?

Thanks,
Matt




Dvdmandt

unread,
Jul 24, 2003, 8:44:31 PM7/24/03
to php-g...@lists.php.net
Warning for </SCRIPT>... It's also the ending for PHP you see... Shouldn't
matter in this case, although, wouldn't suprise me at all if it was...

--
// DvDmanDT
MSN: dvdm...@hotmail.com
Mail: dvdm...@telia.com
"Matt Palermo" <mpal...@vt.edu> skrev i meddelandet
news:001001c35233$f6a89940$4400a8c0@laptop...

Curt Zirzow

unread,
Jul 25, 2003, 2:11:40 AM7/25/03
to php-g...@lists.php.net
* Thus wrote Matt Palermo (mpal...@vt.edu):

No need to echo out the statement, better to use this method so you
dont have to escape each and every " existing:

// leave php to output html ?>


<A href="javascript:go_where_my_variable_says('this.php');">this
page</a>


<SCRIPT LANGUAGE="JavaScript">
<!--
function go_where_my_variable_says(where)
{
document.forms[0].action = where;
document.forms[0].submit();
}
//-->
</SCRIPT>

<?php // now back in php mode

>
> This displays the link fine for the submit hyperlink, but it gives the
> javascript error:
>
> Error: Object doesn't support this property or method.
> Code: 0
>
> Like I said before, this code works perfectly fine if I have it an html
> document.
>
> Anyone got any ideas?

With that being said I dont see a php problem here.


Curt
--
"I used to think I was indecisive, but now I'm not so sure."

Matt Palermo

unread,
Jul 25, 2003, 8:05:57 AM7/25/03
to Comex, php-general
Actually, I found out what the problem is. I have a normal submit button in
the same page, however when I take out the submit button, the javascript code
works fine. When I put the submit button back in, I get the error again. Is
there a fix for this, or do I need to make the submit button into a link
instead?

Thanks,
Matt

>===== Original Message From Comex <n...@xemoc.cjb.net> =====
><3F46E4C7@zathras>
>Matt Palermo:
>> I just remembered (I'm not sure if it makes a difference) that I am
>> using frames on this page. Does this matter at all? Thanks.
>>
>> Matt
>
>No, it doesn't... well it shouldn't anyway. Check the source code of the
>outputted page. Is it exactly what you want it to be? If not, you might
>want to try using single quotes...
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


Matt Palermo

unread,
Jul 25, 2003, 7:23:22 AM7/25/03
to Curt Zirzow, php-general
I have tried this method as well, but I still seem to get the same error. I
have the form tag put in there and everything, with this bit of script inside
the tags, but still no luck. Is there an easier way to accomplish what I want
to do? Please let me know if there is. Thanks.

Matt

>===== Original Message From Curt Zirzow <cu...@zirzow.dyndns.org> =====

Comex

unread,
Jul 25, 2003, 7:45:21 AM7/25/03
to php-g...@lists.php.net

Matt Palermo

unread,
Jul 25, 2003, 7:30:43 AM7/25/03
to Jim Lucas, Matt Palermo, php-general
I just remembered (I'm not sure if it makes a difference) that I am using
frames on this page. Does this matter at all? Thanks.

Matt

>===== Original Message From Matt Palermo <mpal...@vt.edu> =====
>Fixing the javascript that you specified still gave me the same
>errors... Got any more suggestions?
>
>Thanks for your help,
>
>Matt
>
>-----Original Message-----
>From: Jim Lucas [mailto:php...@zonedzero.net]
>Sent: Thursday, July 24, 2003 6:40 PM
>To: Matt Palermo
>Subject: Re: [PHP] Link acting as a submit button
>
>Your javascript is wrong.
>
>change this


> document.forms[0].action = where;

>to this
> document.forms[0].action.value = where;
>
>Jim Lucas

>> This displays the link fine for the submit hyperlink, but it gives the
>
>> javascript error:
>>
>> Error: Object doesn't support this property or method.
>> Code: 0
>>
>> Like I said before, this code works perfectly fine if I have it an
>html
>> document.
>>
>> Anyone got any ideas?
>>

>> Thanks,
>> Matt

Comex

unread,
Jul 25, 2003, 8:07:55 AM7/25/03
to php-g...@lists.php.net
<3F473B32@zathras>
Matt Palermo:

> Actually, I found out what the problem is. I have a normal submit
> button in the same page, however when I take out the submit button,
> the javascript code works fine. When I put the submit button back
> in, I get the error again. Is there a fix for this, or do I need to
> make the submit button into a link instead?
>
> Thanks,
> Matt
>

But you say it works in a HTML page. So I still think you should check if
the output is right.


Skate

unread,
Jul 25, 2003, 8:11:47 AM7/25/03
to Matt Palermo, Comex, php-general
what is the javascript on it? sorry, missed the start of the thread...

----- Original Message -----
From: "Matt Palermo" <mpal...@vt.edu>

Comex

unread,
Jul 25, 2003, 8:23:07 AM7/25/03
to skate, Matt Palermo, php-general
<ro...@fatcuban.com>
skate:

> what is the javascript on it? sorry, missed the start of the thread...
http://tinyurl.com/i0un

Ray Hunter

unread,
Jul 25, 2003, 10:19:18 AM7/25/03
to php-g...@lists.php.net
> (this is in a file called index.html)
> <A href="javascript:go_where_my_variable_says('this.php');">this
> page</a>

try this

<a href="javascript: go_where_my_variable_says('<?php echo
$PHP_SELF;?>');">this page</a>


--
BigDog

Ray Hunter

unread,
Jul 25, 2003, 10:31:06 AM7/25/03
to php-general
On Fri, 2003-07-25 at 05:30, Matt Palermo wrote:
> I just remembered (I'm not sure if it makes a difference) that I am using
> frames on this page. Does this matter at all? Thanks.

Yes it matters tons with the javascript call.

Here is some info on it...however, these questions are now javascript
and not php...

1. make sure you pass in a valid page to your function.
2. make sure that you have a form that you are accessing.
3. make sure that when you access the form you are accessing the correct
frame page.

Example: when you set up the frames use the name attribute to assign
names to the frames...

so if you have a frame named frame1...then you can do this...

frame1.document.forms[0].action.value = where;
frame1.document.forms[0].submit;

I might be off on this a little but that should get you started in the
right direction.

--
BigDog

Matt Palermo

unread,
Jul 25, 2003, 10:48:19 AM7/25/03
to big...@venticon.com, php-general
I found out that it works fine without the submit button that I had in there.
When I take the submit button out, it works, if I put it back in there I get
the error message again.

Any ideas?

Matt

>===== Original Message From big...@venticon.com =====

Jay Blanchard

unread,
Jul 25, 2003, 11:02:17 AM7/25/03
to Matt Palermo, big...@venticon.com, php-general
[snip]

I found out that it works fine without the submit button that I had in
there.
When I take the submit button out, it works, if I put it back in there I
get
the error message again.

Any ideas?
[/snip]

Are you naming the submit buttons? Not just value, but id or name? You
must keep them seperate.

HTH!

Ray Hunter

unread,
Jul 25, 2003, 11:05:06 AM7/25/03
to Jay Blanchard, Matt Palermo, php-general
Why do you have a submit button and a link to submit the form. Dont u
want them to use the submit button for the form?

--
BigDog

Matt Palermo

unread,
Jul 25, 2003, 12:06:50 PM7/25/03
to big...@venticon.com, Jay Blanchard, php-general
Okay, I got it to work. I just put the "id" parameter in the submit button
tag and it works fine now. Thanks for all your help guys...

>===== Original Message From big...@venticon.com =====

Jim Lucas

unread,
Jul 25, 2003, 2:16:37 PM7/25/03
to Matt Palermo, php-general
Depends, are you trying access the form from a different frame?

Jim Lucas
----- Original Message -----
From: "Matt Palermo" <mpal...@vt.edu>

To: "Jim Lucas" <php...@zonedzero.net>; "Matt Palermo" <mpal...@vt.edu>;
"php-general" <php-g...@lists.php.net>

Daemorhedron

unread,
Jul 25, 2003, 2:28:18 PM7/25/03
to php-g...@lists.php.net
Another option might be to use the heredoc syntax, but having php echo your
html is not the most effecient. Just FYI.

http://ca.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc


"Matt Palermo" <mpal...@vt.edu> wrote in message
news:001001c35233$f6a89940$4400a8c0@laptop...

Comex

unread,
Jul 25, 2003, 5:49:06 PM7/25/03
to php-g...@lists.php.net
<1059143464.1...@bigdog.info.trw.com>
Ray Hunter:

> On Fri, 2003-07-25 at 05:30, Matt Palermo wrote:
>> I just remembered (I'm not sure if it makes a difference) that I am
>> using frames on this page. Does this matter at all? Thanks.
>
> Yes it matters tons with the javascript call.
>
> Here is some info on it...however, these questions are now javascript
> and not php...

That's only if you're going between frames, if the whole form (as usual) is
on one frame it works fine.


Ray Hunter

unread,
Jul 25, 2003, 6:35:48 PM7/25/03
to php-g...@lists.php.net
Good point...thanks for catching that

I usually link into forms from other frames if I dont have a submit
button in that form.

--
BigDog

0 new messages