My Script isnt working

Squishinator

New Member
Reaction score
3
I am extremely new to this stuff, so be kind. Why wont this work?


Code:
<script type="text/javascript">
function newPage()
if (form.jiggy2.checked)
{alert("yay")}
</script>

<form>
<input type="checkbox" name="jiggy1" value="who cares 1?" />1<br />
<input type="checkbox" name="jiggy2" value="who cares 2?" />2<br />
<input type="button" name="button" value="Click Me" onClick="newPage()">
</form>
 

TFlan

I could change this in my User CP.
Reaction score
64
Code:
<html>
<head>
<script type="text/javascript">
function newPage(){
	if([COLOR="Red"]document.form1.jiggy2.checked[/COLOR]){
		alert("yay");
	}
}
</script>
</head>
<body>
<form [COLOR="Red"]name="form1"[/COLOR] method="post" action="#">
	<input type="checkbox" name="jiggy1" value="who cares 1?" />1<br />
	<input type="checkbox" [COLOR="Red"]name="jiggy2"[/COLOR] value="who cares 2?" />2<br />
	<input type="button" name="button" value="Click Me" onClick="newPage()">
</form>
</body>
</html>
 

TFlan

I could change this in my User CP.
Reaction score
64
It's working for me in both IE 7 / 8 and FF.

Are you sure you copied it correctly? Form name is correct? Field name is correct? No syntax errors?

If you use Firefox, open your page, hit ctrl+shift+j, hit clear, then refresh your page.

Does an error show up?
 

Squishinator

New Member
Reaction score
3
It turns out i missed something.

Now this isnt working:

Code:
<html>
<head>
<script type="text/javascript">
function newPage(){
      var a=form1.jiggy2.value
      document.write(a);
</script>
</head>

<body>
<form name="form1" method="post" action="#">
	<input type="text" name="jiggy2" />
	<input type="button" name="button" value="Click Me" onClick="newPage()">
</form>
</body>
</html>
 

UndeadDragon

Super Moderator
Reaction score
447
You missed a }.

Code:
function newPage(){
      var a=form1.jiggy2.value
      document.write(a);
[B]}[/B]
 

Squishinator

New Member
Reaction score
3
thanks, now i have just 2 more questions lol.

1. How do you replace the text or add text or whatever to a div, body, whatever.

2.How does this website add posts?
 

UndeadDragon

Super Moderator
Reaction score
447
1.
Code:
window.document.getElementById("DIV ID").innerHTML = a;

2. It uses PHP and stores posts in a database.
 

TFlan

I could change this in my User CP.
Reaction score
64
Code:
<html>
<head>
<script type="text/javascript">
function newPage(){
      var a = [COLOR="Red"]document.[/COLOR]form1.jiggy2.value[COLOR="Red"];[/COLOR] <!-- The ';' is not required, but is good coding practice -->
      document.write(a);
[COLOR="Red"]}[/COLOR]
</script>
</head>
<body>
<form name="form1" method="post" action="#">
	<input type="text" name="jiggy2" />
	<input type="button" name="button" value="Click Me" onClick="newPage()">
</form>
</body>
</html>

A combination of a MySQL database to store the information and PHP to retrieve and process that information.

http://www.tizag.com/

That is the website I used when I first started out, very helpful.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top