Phphelp
Phphelp

Reputation: 1330

button inside href

Is it ok to write like this?

<a href="add-lead-new.php" target="rightframe"><input type="button" value="New booking" /></a>

The link should look like a button but it should open in the right part of the page. If its wrong, is there any other way to do it? The above code works fine. i just don't know if its the correct way to do it. Thanks

Upvotes: 3

Views: 42929

Answers (6)

JefWit1F
JefWit1F

Reputation: 11

This is what worked for me.

<a><?php echo( "<button onclick= \"location.href='inc/name_of_php_file.php'\">your buttons name goes here</button>");?></a>

In other words nest your desired php code block inside an anchor element to 'link' it. Then add the php code block and inside that code block you'll want to add an echo(). Inside that echo you want to add your HTML code like normal. As if you weren't even writing in PHP.

Edit the folder name and file to your desired location. And then finally edit what text you want your button to show your viewers.

onclick= \"location.href='folder_name_goes_here/name_of_php_file_goes_here.php'\">your buttons name goes here

This should link to your page with your desired caption.

Please keep in mind the \" as this is utterly important. Without \ in front of the " your code wont read correctly due to the many "s found nested inside each other. \ allows HTML to ignore the first " as an end to the echo Sting.

Upvotes: 0

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94319

Yours is working but this is better,

<input type="button" value="New booking" onClick="top.frames['rightframe'].src='add-lead-new.php'" />

Upvotes: 0

No, this is not allowed according to the HTML5 specification.

The button will probably show up, but since you're violating the specification it may not behave as you want. You should avoid doing this.


The most reliable to way to make a button bring the user to a page is to create a <form> that targets that page, and make the button submit that form.

<form action="add-lead-new.php"><input type="submit" value="New Booking" /></form>

Upvotes: 7

R&#233;troX
R&#233;troX

Reputation: 2096

It's better to just use CSS, but if you're really stuck on using a physical button, you can create a dummy form with no data:

<form action="href"><input type="submit" value="Click Here" /></form>

Upvotes: 1

iHaveacomputer
iHaveacomputer

Reputation: 1437

no, the button itself wont do anything - it's only usefull with javascript to trigger any functions. you should use css to make some of your links like a button: http://www.zurb.com/article/266/super-awesome-buttons-with-css3-and-rgba

Upvotes: 3

Cystack
Cystack

Reputation: 3561

<input type="button" value="New booking" onclick="self.frames['rightframe'].location.href='add-lead-new.php'"/>

would be ok

Upvotes: 1

Related Questions