[solved]javascript button link

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

[solved]javascript button link

Post by vigge89 »

I've got the following code for an button on my page:

Code: Select all

<input type='button' value='register'  OnCLick="document.location.href=('register.php');">
but, it doesn't work.
could anyone tell me what im doing wrong?
Last edited by vigge89 on Sun Feb 22, 2004 5:33 pm, edited 1 time in total.
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

<form id="register" action="register.php" method="post"><!-- or get -->
<input type="submit" value="register" id="submit"><!-- id is for various uses -->
</form>

this should work, you don't need a script, just make sure your url in the action="URL" is correct.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

that's kinda long, and my script HAVE worked before, but it doesn't now
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

There is only one problem with using a java script to post your submit button.

If someone has java disabled, which many people do, it won't work.

Just my .02 cents. 8)
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

@memories

I see you use id's instead of name's for fields. I know this is the right way but i can't make it work with my code.

eg:
<input type="text" id="test" />

won't work with :
echo $_POST['test'];

:roll:

name's instead work.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

are there any other way to make a button-link?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

i've discovered that the following code works in IE, while it doesn't in Mozilla Firefox :(

Code: Select all

<input type='button' value='register' onClick="document.location.href='register.php';">
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

basdog22:

Actually with xHTML and forms, the W3C recomends using both the id and name attributes for compatability.

But the stricter your DOC declaration is, the less xHTML relies on the name attribute for forms. And this is for forms only. I do not think name is allowed in any other instance.

vigge89:

If you're having problems with the form wankering out of place, use CSS to position it to the parent container. And if it's in a table, make sure your CSS has the margins set for table form for stupid IE.

An example of the CSS might look like this.

CSS -->

table form {
margin: 0px 0px 0px 0px; /* top, right, bottom, left respectively */
padding: 0px 0px 0px 0px;
}

#register {
position: absolute; /* or relative but use margins for relative positions */
top: 20px;
left: 20px
}

#submit {
color: #000;
background: #cfc;
boder: 1px solid #000;
}

xHTML -->

<form id="register" action="register.php" method="post">
<input type="submit" value="register" id="submit" />
</form>

And even this is not the proper way to make a form in xHTML. There are other elements for proper form markup that should be inserted. For more info see the W3C site on forms for 4.01 strict --> http://www.w3.org/TR/html401/interact/forms.html
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

CSS?
what does that have to do with my javascript?
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post by no_memories »

vigge89 said:
are there any other way to make a button-link?
no_memories said:
There is only one problem with using a java script to post your submit button.
If someone has java disabled, which many people do, it won't work.

Just my .02 cents.
CSS is the backbone of xHTML and the future of markup. If a site has good markup, well structured and modular PhP can be used. CSS takes out the redundant nature of HTML and modulates it without using tables or sloppy markup. Modulation is what it's about. mmmm-k I'm done with this topic ;)
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

well, i don't see why i should use that CSS-stylesheet, i've already positioned the button ,i just need the code for Firefox button-links...
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post by evilMind »

I've found that onclick works more often than OnClick or onClick or any other type of capitalization.

I use onclick="" all the time and have had 0 problems with it (using any browser)..
It may be that you simply need to change your OnClick to onclick :)

Code: Select all

<input type="button" value="register" onclick="document.location.href='register.php';">
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

you solved the problem!
lol @ FireFox 0.8 :P
Post Reply