1.11M Members

scriptlet in javascript

 
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:

 
0
 

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

 
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

Question Answered as of 5 Years Ago by javaAddict and amarjeetsingh
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article