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

asp/java mix

Status
Not open for further replies.

ItHurtsWhenIThink

Technical User
Sep 1, 2007
60
US
I need to retrieve a form field name from my page and dump it into some java script. The form fields are created dynamically in an asp page.

here are the pertinent parts of the code:

chkLeave(var) {

if (window.document.form1.frmLeaveCode.value==window.document.form1.frmCode.value)

So I need help in making "frmLeaveCode" and "frmCode" above dynamic. Q: how can I make those "var & frmLeaveCode" or "1frmLeaveCode" where var=1


//var is the progressive number that allows me to identify each form field

// in my asp page the form is created using the following (I have cleaned it up a bit for simplicity):



<select name="<%=intCount & "frmLeaveCode"%>" onChange="chkLeave(<%=intCount%>);">

Hope this makes sense.

Mike...
 
Get the data from the form collection into a variable and response.write it into the appropriate place in the code.





Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Mike
Your original post does not name sense for me...
Are you tryinh to create one page with 2 forms inside? Why?
You can create dynamic elements like
<select name="<%=intCount %>frmLeaveCode" onChange="chkLeave('<%=intCount%>');">
so it will be converted to something like
<select name="1frmLeaveCode" onChange="chkLeave('1');">
<select name="2frmLeaveCode" onChange="chkLeave('2');">
etc;
for form validation you can use javascript or jquery and get all form elements, loop throw and chack values...
after submitting form on next page you have requesr.form object which was all form elements inside with values. Which part of that is your problem?



 
gk53 correct.

In fact that is what I am doing.

Essentially, my form has a member drop down list. When the user changes that name to a different user I want to have a new form filed pop up on the form.

BUT if they select a new member and then change back to the original member I want to have that form field disappear.

So my chkLeave() need to evaluate if there was a change. PROBLEM is I have several members on the same form.

I use exactly what you have on the form side:

<select name="<%=intCount %>frmLeaveCode" onChange="chkLeave('<%=intCount%>');">

My question is how do I handle that on the java side
Here is what I have so far (only code needed for discussion).

if (window.document.form1.frmLeaveCode.value==window.document.form1.frmLeaveCode.value)
{
div.style.display = 'none';
}
else
{
div.style.visibility = 'visible';
}


So my question is how do I concatenate the 'intCount' value to the 'form1.frmLeaveCode.value' in the javascript side.

 
Let me clear understand what is page logic.
1. You have a form with original member info.
2. When in member dropdown list user changed selection you displaying somewhere identical form with selected user. right?
Is that form shows in the same window or it is popup? If popup how it was done iframe, winodw.open, modal, div with overlay?
3. is "popup form has another member dropdown and works similat to original?
4. Why you need to find oth values? If you need to compare original value to dinamic one, why no to send in "dynamic" item value as paramemter?

And if you really still need that
allLeaveSelections = $('[id^=frmLeaveCode]');
jquery which return to you array of all elements which id starts from "frmLeaveCode"
of couse you need to modify
<select name="<%=intCount %>frmLeaveCode" onChange="chkLeave('<%=intCount%>');">
to <select id="<%=intCount %>frmLeaveCode" name="<%=intCount %>frmLeaveCode" onChange="chkLeave('<%=intCount%>');">
and include link to jquery library which you can get on that link copy from browser and save in "jquery-1.10.2.js" file and include this javascript in your page
 
forum216

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
@ChrisHirst

I directed the OP here from the js forum.
the issue (as originally expounded) was how to use ASP to insert variables into rendered client-side javascript. I provided a solution along the lines of
Code:
var someVar = "<%= some asp variable %> ";
however the OP never responded; so I assume that this was not a solution for him/her (although I see he now says he is using it...)

i have read the later post and wonder about this line

Code:
if (window.document.form1.frmLeaveCode.value==window.document.form1.frmLeaveCode.value)

my guess is that will always evaluate to TRUE ;-)
 
Theoretically no, because each 'frmLeaveCode' should have the 'intCount' value concatenated to it.

So it might look like:

if (window.document.form1.1frmLeaveCode.value==window.document2form1.2frmLeaveCode.value)

OR

if (window.document.form1.1frmLeaveCode.value==window.document.form1.1frmLeaveCode.value)

OR

if (window.document.form1.3frmLeaveCode.value==window.document.form1.2frmLeaveCode.value)

My question is "How do I concatenate the intCount value to the frmLeaveCode in the javascript function.
 
if (window.document.form1.<%= intCount %>frmLeaveCode.value==window.document.form1.<%= intCount - 1%>frmLeaveCode.value)
but i do not think it will work
 
Tell you what: provide a link to your site where we can see this in action or paste the rendered code you are using.

Your posts are unfortunately not clear enough for (at least) me to grok fully what you want. Your original question however has been asked and answered at least twice.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top