Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Form/Checkbox Question

Status
Not open for further replies.

vetteguy69

Technical User
Feb 22, 2002
13
0
0
US
Hello All,
I have a page with a text link that goes to another page with a form on it that includes checkboxes. If the user clicks the text link on pageA I want to go to pageB(page with form) and check off a certain checkbox. I have the following javascript in the header of pageB now but it doesn't seem to work. Any help is greatly appreciated.

<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
if (document.referrer == &quot;pageA.htm&quot;)
document.form.box1.checked==true;
</script>

Any suggestions?
Thanks in advance,
Mike
 

Mike,

Try replacing the == with = in the second line:

Code:
document.form.box1.checked==true;

Hope this works ;o)

Dan
 

Mike,

Try replacing the == with = in the second line:

Code:
document.form.box1.checked=true;

Hope this works ;o)

Dan
 
Hehe damn.. my first post got through before i removed the = sign ;o)

The line should read as per the second post.

Dan
 
You might want to do that in the onLoad event, however... Otherwise you could be setting a checkbox that doesn't exist yet:

Code:
<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
function setupPage()
{
	if (document.referrer == &quot;[URL unfurl="true"]http://www.yourdomain.com/pageA.html&quot;)[/URL] document.myForm.box1.checked = true;
}
</script>

...

<body onLoad=&quot;setupPage();&quot;>

Hope this helps!

Dan
 
I tried using the onLoad and it still doesn't check off the box I want. I'm not sure what else to try. here's the code I'm using:

<script type=&quot;text/javascript&quot; language=&quot;javascript&quot;>
function setup()
{
if (document.referrer == &quot;pageA.htm&quot;)
document.form.boxname.checked = true;
{
</script>

<body onLoad=&quot;setup();&quot;>

any ideas?
Thanks for the posts so far!
=Mike
 

It won't work locally - you have to have the page on a server for document.referrer to work, as far as I know.

Are you testing it locally?

Dan
 
No I'm testing it on a live server. I even put an alert box inside the function to make sure my page is reading it, it is but the box doesn't get checked off ?!?!

=mike
 
First try fixing the JavaScript error - you have an open brace instead of a close brace at the end of function setup();

If that doesn't work, try changing your form name from &quot;form&quot; to &quot;myForm&quot; or something. Form could well be a reserved word.

If all else fails, do an
Code:
alert(document.referrer)
inside the function, and make sure your string is equal to that value.

Hope this helps!

Dan
 
That wrong bracket did it. Thanks very much for your speedy responses and help Dan. It's greatly appreciated.

=Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top