0

hii..
I want to use a scriplet variable in javascript.
i used
<%! int i;>
<% i=0; %>
<input type="text" id="itemValue" onchange=changeValue('<%i%>')>

it works fine if i give alert(i) in
changeValue function.
Otherwise it gives error i is undefined.
Plz help me. I don't want to bother user by increasing one user click.
Plz help what is the reason ????

i m using struts 1.2

:confused:

3
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by mamatachaudhari
0

Try this:
changeValue('<%=i%>')

Thanks for reply....
It's not working..
when i first time load my project it gives me error like i is undefined
But after giving an alert it works fine...

0

Thanks for reply....
It's not working..
when i first time load my project it gives me error like i is undefined
But after giving an alert it works fine...

What do you mean giving an alert. Post the code that works

0

What do you mean giving an alert. Post the code that works

This is my input text field

<input type="text" id="productQuantity" size="5"  onchange="changeQuantity(this.form,'<bean:write property="productCode" name="product"/>','<%=z %>');"/>

And this is my javaScript function is..

function changeQuantity(form,productCode,index)
			{
				//alert("z==="+productCode);
				lengthOfItems=form.productCombo.options.length;
				lengthOfProducts=form.productCombo2.options.length;
alert("index"+index);
changeItemValueNew(form,productCode,index);
}

after giving that alert messsage it works otherwise not.

}

0

First of all describe better what do you mean by this:
after giving that alert messsage it works otherwise not.

Also, firstly does the method being called correctly?

Try this to check the above:

function changeQuantity(form,productCode,index)
{
alert("Method called");
}

Then see if the arguments are passed correctly:

function changeQuantity(form,productCode,index)
{
alert(productCode);
alert(index);
}

Then try your code with alert messages between the other commands (like debugging) to see what is wrong

0

Create the variable in the javaScript
and store the value in it
then use it

function changeQuantity(form,productCode,index)
{
 var   z=productCode;
var y=index;
lengthOfItems=form.productCombo.options.length;
lengthOfProducts=form.productCombo2.options.length;
alert("index"+index);
changeItemValueNew(form,z,y);
}
0

Create the variable in the javaScript
and store the value in it
then use it

var   z=productCode;
var y=index;

I don't believe that it will solve the problem. If this will execute correctly:

var   z=productCode;

changeItemValueNew(form,z,y)

then this will also:

changeItemValueNew(form,productCode,index);
0

Create the variable in the javaScript
and store the value in it
then use it

function changeQuantity(form,productCode,index)
{
 var   z=productCode;
var y=index;
lengthOfItems=form.productCombo.options.length;
lengthOfProducts=form.productCombo2.options.length;
alert("index"+y);
changeItemValueNew(form,z,y);
}

if you do calulation in java script, then you must be attentative
about the data type of the variable

java script is not strictly check the datatype of the variable

i do n't know what have you done in

changeItemValueNew(form,z,y)

method

0

i do n't know what have you done in

changeItemValueNew(form,z,y)

method

We still don't know if the code before the call of that method is executed

0

Create the variable in the javaScript
and store the value in it
then use it

function changeQuantity(form,productCode,index)
{
 var   z=productCode;
var y=index;
lengthOfItems=form.productCombo.options.length;
lengthOfProducts=form.productCombo2.options.length;
alert("index"+index);
changeItemValueNew(form,z,y);
}

thanks.. Its working perfectly

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.