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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a var value

Status
Not open for further replies.

SDyke

MIS
Oct 13, 2005
55
US
I am using javascript in a lotus notes web client. The following code creates an error:

function displayWarning(){
stop_order_flag = new String(window.document.forms[0].dm_stop_order.value);
}

window.document.forms[0].dm_stop_order.value is null or not an object

Please help
 
What the error is telling you is that window.document.forms[0].dm_stop_order does not exist on your page. This could mean a few things. Either there's no forms on your page, or there's no element with a name of dm_stop_order on the page, or specifically there's no element with the name dm_stop_order in the first form on the page. Without seeing the markup for the page it's impossible to tell you which of those problems I've listed that it is.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Try removing the window part from your object -think it'll solve your problem.

Change this :
Code:
window.document.forms[0].dm_stop_order.value

To this :
Code:
document.forms[0].dm_stop_order.value
 
consequently, your code should be

Code:
stop_order_flag = document.forms['your_form_name'].elements['dm_stop_order'].value;

or, preferably:

Code:
stop_order_flag = document.getElementById('yourFieldId').value;



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I think you are right about the form not existing.

On an intranet web page a link opens a notes form with a prompt box. User types a number in and a document opens with data pertaining to number. My desire is to have an alert pop up if a certain field contains a specific text string. However I can't seem to get my syntax right in the JS Header to poll for the value of a field.
 
When I try:

stop_order_flag = document.getElementById('yourFieldId').value;

I get message that 'Object is required'
 
You need to use the ACTUAL field name you're looking for, not just copy and paste examples given here. Do you actually have a field named yourFieldId? Or is it named dm_stop_order?

As well, I'd break it into 2 steps to see if the element exists before trying to access its value.

Code:
var element = document.getElementById('yourFieldId');

if (element)
  {
  var stop_order_flag = element.value;
  }

Lee
 
This code returns 'undefined' Even though I do have a field named 'DM_STOP_ORDER' and it have a string value also.

function displayWarning(){

var element = document.getElementById('DM_STOP_ORDER');

if (element)
{
var stop_order_flag = element.value;
}

alert(stop_order_flag);

}
 
Is the element named DM_STOP_ORDER, or does it have the id DM_STOP_ORDER? The function clearly is called getElementBy[/red]Id[/red].

Lee
 
Make that getElementBy[red]Id[/red].

There's also a method document.getElementsByName() that returns an array of elements with the specified name, and you have to access it as an array.

Lee
 
I am getting closer but this code returs "Hit" even when redlineflag and element3 do not match.

function displayWarning(){

var element = document.getElementById('DM_STOP_ORDER');
var element2 = document.getElementById('DM_FILES2');
var element3 = new String("SEE REDLINE DRAWING");

if (element)
{
var stop_order_flag = element.value;

}

if (element2)
{
var redlineflag = element2.value;

}

if(stop_order_flag)
{
alert("There is a Stop Issued for this Drawing");
}

if(redlineflag=element3)
{
alert("Hit");
}
else{
alert("None")
}
}
 
Never mind. I just realized I need == to compare variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top