1,105,644 Community Members

scriptlet in javascript

Member Avatar
mamatachaudhari
Newbie Poster
20 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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:

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
0
 

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

Member Avatar
mamatachaudhari
Newbie Poster
20 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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...

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
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

Member Avatar
mamatachaudhari
Newbie Poster
20 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

}

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
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

Member Avatar
amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: -8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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);
}
Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
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);
Member Avatar
amarjeetsingh
Newbie Poster
21 posts since Feb 2009
Reputation Points: -8 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
javaAddict
Nearly a Senior Poster
3,274 posts since Dec 2007
Reputation Points: 900 [?]
Q&As Helped to Solve: 448 [?]
Skill Endorsements: 8 [?]
Team Colleague
Featured
 
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

Member Avatar
mamatachaudhari
Newbie Poster
20 posts since Apr 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 4 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