Page 1 of 1

[solved]javascript button link

Posted: Sun Feb 22, 2004 11:24 am
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?

Posted: Sun Feb 22, 2004 12:52 pm
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.

Posted: Sun Feb 22, 2004 1:19 pm
by vigge89
that's kinda long, and my script HAVE worked before, but it doesn't now

Posted: Sun Feb 22, 2004 1:28 pm
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)

Posted: Sun Feb 22, 2004 1:51 pm
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.

Posted: Sun Feb 22, 2004 2:01 pm
by vigge89
are there any other way to make a button-link?

Posted: Sun Feb 22, 2004 2:09 pm
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';">

Posted: Sun Feb 22, 2004 2:24 pm
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

Posted: Sun Feb 22, 2004 2:42 pm
by vigge89
CSS?
what does that have to do with my javascript?

Posted: Sun Feb 22, 2004 3:19 pm
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 ;)

Posted: Sun Feb 22, 2004 3:22 pm
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...

Posted: Sun Feb 22, 2004 4:18 pm
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';">

Posted: Sun Feb 22, 2004 5:33 pm
by vigge89
you solved the problem!
lol @ FireFox 0.8 :P