onclick is not working

JavaScript and client side scripting.

Moderator: General Moderators

joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

onclick is not working

Post by joecrack »

i want to forward the browser with this script when clicking on a button.
the button is also a sumbit buttn for data that will be sent to sql.
I dont want to open a popup, just forward the window.

Code: Select all

<script type="text/javascript" language="javascript">
function click ()
{
  location.href = "www.web.de";
}
</script>

Code: Select all

<input name="button" type="submit" value="update" onklick="click()">
So how do i make it work??
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

onClick not onKlick
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

uuups - :roll: sorry
but still i does not work!!!
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Worked for me when I added a semicolon to the input tag's on click...

onclick="click();"
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

doesnt work!!!
if the one semicolon was the only thing that you changed, then it has to be something with my browser ???
or could it be tat it is sometingwith the button, that you cankt have submit an onclick or whatever ???
just to be sure:

Code: Select all

<script type="text/javascript" language="javascript">
function click() {
  location.href = "www.web.de";
}
</script>

Code: Select all

<input name="knopf" type="submit" value="update" onclick="click();">
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Code: Select all

<html>
<head>
<script type="text/javascript" language="javascript">
function myClick ()
{
  location.href = "http://www.yahoo.com";
}
</script>
</head>
<body>

<input name="button" type="button" value="update" onclick="myClick();">
</body>
</html>
Just did this in FF; worked.
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

so the problem is the type=""
when it put in type="button" it is working - with sumbit its not.
but it as to be a submit button, cause it has to sent the data to sql.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

So in your form tag add a onsubmit="myClick();"

But that begs the question, why are you using a JS redirect when you can just use your form action attribute?
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

the onsubmit is not working.
how would a action tag lok like???
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Code: Select all

<form name="myform" action="mypage.php" method="post">

<input type="submit" name="submit" value="submit">
</form>
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

okey - now its opening a new site .. but the submit is not working anymore ...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Please post your full code... we're all just guessing here :)

I can't see any reason why it wont work based on what you posted.... you're sure JS isn't disabled in your browser?

What does this do (just a test);

Code: Select all

<script type="text/javascript">
<!--
alert('JS is working Fine and Dandy!');
// -->
</script>
<noscript>
Sorry but JS isn't turned on
</noscript>
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

@d11wtq
It tells me that JS working fine!!!
The code is too long - its like 3pages, because it a huge php code.
I hope ifi post this part its enough:

Code: Select all

<br><br>
Which Order you want to update?<br>
<br>
<table width="504">
	<form action="back.htm" method="post">
  <tr>
    <td width="167"><div align="right">Type the Projekt Number:</div></td>
    <td width="325"><input name="projnr" type="text" id="projnr" length="3">
      (cant be changed) </td>
  </tr>
  <tr>
    <td><div align="right">Customer Number:</div></td>
    <td><input name="customernr" type="text" id="customernr" length="3"> 
      (cant be changed) </td>
  </tr>
  <tr>
    <td><div align="right">Contract Date:</div></td>
    <td><input name="contrdate" type="text" id="contrdate" length="3"> 
      (cant be changed)</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div align="right">
      <input name="knopf" type="submit" value="update">
    </div></td>
  </tr>
	</form>
</table>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

joecrack wrote:okey - now its opening a new site .. but the submit is not working anymore ...
what do you mean it's opening a new site? You mean it's taking you to the action page (which btw is a .htm page)?

that's what it's supposed to do...what exactly do you want this to do?
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

i mean now it is moving to the next url but .. the submit to the sql database does not work anymore^^
it is htm page yeah
Post Reply