I am a novice when it comes to javascripting. I have the following code on a form in the JSheader:
var myForm = document._FormName;
if ( myForm.WizardState.value = 1)
{
document.write(“”)
}
On the form I have declared WizardState=1 in a hidden field. What I am confused about is, the code does not come back with a Script Error, but it still does not redirect me to the specified website. What could be wrong? Is it that it is in the header, and can not recognise the hidden field? or something else?
Subject: Javscripting issue?
Apart from Christopher’s comment, the field will not exist at the time this code runs (it doesn’t occur until lower in the document, and inline code executes as it occurs). You would be able to access the field, provided that it appears as part of the HTML document, from a point lower in the document or from code fired in the onload event (which means is out of the question).
However, you can access even the hidden-est hidden field in Notes, and JavaScript isn’t the only way to create variable HTML. Try this in the HTML Head Content object:
@If(WizardState = “1”; “<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://www.xyz.com">”; “”)
Subject: RE: Javscripting issue?
Good point and suggestion Stan.
Subject: RE: Javscripting issue?
I tried what you suggested with the @If…nothing. I also called it in the onload, and nothing.
Subject: RE: Javscripting issue?
Is WizardState a text field or a number field? The code definitely works (I use similar code all over the place), so the condition in the @If is probably wrong. I believe I mentioned that the onload won’t work (you can’t place in the location from which the code was called).
Subject: Javscripting issue?
ok, that worked stan…but that only solved one issue. Here is the full code I have in the header…and I am calling it using the onload:function changeVal() {
//if ( !theForm ) theForm = document.forms[0];
var theForm = document._FormName;
if ( theForm.WizardState.value = 1)
{
document.write(“hello”)
}else{
document.write("it worked")}
}
the problem now is that a script error comes up saying Object expected…not sure.
Subject: RE: Javscripting issue?
First, I’m going to have to break you of the habit of using the “document.FormName” syntax, since it needs the document.all collection to work – an Internet Explorer object model extension. That means it isn’t going to work properly in a lot of browsers. Much better is:
document.forms[‘FormName’]
or
document.forms[i]
Is the problem occurring in read mode or edit mode?
Subject: RE: Javscripting issue?
Thanks Stan for all the help. I finally got it working…seems the document.forms[i] did not work…needed to define the [i] as [‘FormName’] like you suggested. Thanks again
Subject: RE: Javscripting issue?
ok…thanks for the tip. This is occuring in edit mode…as it is a form that people fill out on the web.
Subject: RE: Javscripting issue?
Just because there’s a form involved doesn’t mean I can assume that this is in edit mode. This is Domino, remember? Existing documents are also displayed using forms.
Apart from the if condition using the assignment operator rather than the equality operator (“=” instead of “++”, which means “check to see if the value of WizardState can be set to 1” rather than "check to see if the value of WizardState IS 1), I can’t see anything terminally wrong unless theForm or the WizardState field or its value is unavailable. Are you sure that’s where it’s failing?
I would suggest testing this in some flavour of Mozilla (I prefer Firefox) so that you can take advantage of the JavaScript console. Internet Explorer has horrible JS error handling, and often lies through its teeth about what’s wrong.
Subject: Javscripting issue?
your javascript cannot access hidden fields unless they are hidden through html attributes (and not notes hidewhen) or you have “generate html for all fields” enabled on the form properties.
Subject: RE: Javscripting issue?
I do have other javascript running (called in the onSubmit) to validate parts of the form, which uses this same WizardState field. I do have “Generate HTML for all Fields” set in the form, but the other javascript works fine, why would this not?