Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Java Script problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Java Script problem " Watch "Java Script problem " New topic
Author

Java Script problem

Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Hi All,

I have the following snippet on my JSP

<html:select property="priority" on change='javascript isableAddress()'>
<html ptions collection="namedInsuredPriority" property="value" labelProperty="name" />
</html:select><br>

and my Javascript function is

<script language='javascript'>
function disableAddress(){
alert("I am here");
var text=document.forms[0].priority.options[document.forms[0].priority.options.selectedIndex].text;
alert(text);
//alert(document.forms[0].firstName.disabled);
document.forms[0].firstName.disabled = true;
//alert(document.forms[0].firstName.disabled);
}
</script>

When I change something on the priority dropdown, I am getting the alert of "I am here" but after that I am getting the javascript error on the page as

Error: 'document.forms.0.priority.options' is null or not an object

Could any one guess what am I messing up here ?

Thanks,
Shanmugam


SJCP 1.4<br />SCWCD 1.4<br />SCEA
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Well that is because the dropdown is probably not named priority, you need to do a view source on the page and see what it is called.

Eric
Shanmugam Muthukumarasamy
Ranch Hand

Joined: Jan 11, 2003
Posts: 83
Eric,

Thanks for the reply,
this is what I see in the Viewsource

<select name="priority" onchange="disableAddress(this.form)"><option value="" selected="selected">Select...</option>
<option value="First">First Named Insured</option>
<option value="Additional">Other Named Insured</option></select>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You could also get this message if there is any other input element named "priority" anywhere in the form.

Also, the selectedIndex property is a property of the select control, not of the options in the control. So, you should be writing:
var text=document.forms[0].priority.options[document.forms[0].priority.selectedIndex].text;


This would be a whole lot easier if you just pass the select object to the javaScriptFunction, something like this

<html:select property="priority" onchange="disableAddress(this)" />

The function would be:

function disableAddress(select) {
var text = select.options[select.selectedIndex].value;
}


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Script problem
 
Similar Threads
onkeydown before onchange event
document.Form1 has no properties error
How to submit a page on change of Combo using Struts
Javascript onPaste
is it possible to have multiple actions in a single page?