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

Dynamically naming form name

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
US
I have a form that uses a dynamic name based on a value.

the value is based on the id of the record. if I use
Code:
onChange="document.form1.submit()"
how can I write the 1 in form 1 to the variable?

Code:
onChange="document.form++id++.submit()"

or something like that?
 
onChange="document.form"+id+".submit()"

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
using this as id3 is the variable name
Code:
onChange="document.form"+id3+".submit()"
[/code
 does not appear to work. on my viewer, "+id3+".submit()" is red as if it isn't written properly so the form is not submitting on the change.
 
Is id3 a valid variable? Does it contain a value?
You need to share all of your code.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Yes id3 is a good variable. I checked the page source and verified that each row does have the id3 form name. the only issue now is passing it. with the submit.

feherke

Code:
onChange="document.forms['form'+id3].submit()"
looks good on the viewer but it does not submit anything on the page. My guess would be the form names aren't matching up, or something like that. Like the form name does not qualify and therefore does not submit.
 
Just a quick question about this, if I use the
Code:
onClick="this.form.submit();"

and each row does have a different form name, shouldn't this work? It doesn't, but shouldn't it?
 
here is the code for the page. As stated, it is sending the information from each row(form)


Code:
<!--#include virtual="myconnectionstringp"-->

	
<%
casetype = request.querystring("casetype")
if casetype = 1 then
	sqltype = "open"
elseif casetype = 2 then
	sqltype = "closed"
else
	sqltype = "open"
end if	
%>



<body>
<table cellpadding="4" cellspacing="0" align="center">
	<tr>
		

<% set orders1 = conn.execute("select * from orders where case_ = '"&sqltype&"'") // i know * shouldn't be used

	
		
		
		irowcolor = 0
if not orders1.eof then
do while not orders1.eof
id3 = orders1.fields.item("id").value
'**** check shipping method ************
vmethod = trim(orders1.fields.item("method_").value)
	if vmethod = "email_" then
		vmethod1 = "Email"
	elseif vmethod = "kit_" then
		vmethod1 = "Ship Kit"
		end if
'**********************************************		
		if irowcolor mod 2 = 0 then
			rowcolor = "#8699C4"
			auto1 = "auto-style4"
		else
			rowcolor = "#86AACE"
			auto1 = "auto-style3"
		end if
		vform = "form"&id3
		'response.write vform
%>
	<form name="<%=vform%>" action="statuschangeasp.asp" method="post">

	<tr style bgcolor="<%=rowcolor%>">
		<td  ><%=orders1.fields.item("id").value%></td>
		<td  >
		<span id="c10_ctl">
		
		<select  onChange="document.forms['form'+id3].submit()"  name="change_">
		<option selected="<%=orders1.fields.item("istatus_").value%>" value="<%=orders1.fields.item("istatus_").value%>"><%=orders1.fields.item("istatus_").value%></option>
		
		<option value="Shipped">Shipped</option>
		<option value="Sent">Sent</option>
		<option value="paid1">Paid PayPal</option>
		<option value="paid2">Paid Check</option>
		<option value="received">Received</option>
		<option value="processing">Processing</option>
		<option value="processed">Processed</option>
		<option value="returned">Returned</option>
		<option value="Pending">Pending</option>
		</select>
			<input name="id" type="hidden" value='<%=orders1.fields.item("id").value%>' class="auto-style4"/>
			
			</span>
			</td>
		<td class="auto-style3" ><%=orders1.fields.item("tracking_").value%></td>
		<td class="auto-style3" ><%=vmethod1%></td>
		<td class="auto-style3" ><%=orders1.fields.item("first_").value%></td>
		<td class="auto-style3" ><%=orders1.fields.item("last_").value%></td>
		<td class="auto-style3" ><%=orders1.fields.item("state_").value%></td>
		<td class="auto-style3" ><%=orders1.fields.item("email_").value%></td>
		<td class="auto-style3" ><%=orders1.fields.item("phone_").value%></td>
		<td class="auto-style3" ><%=orders1.fields.item("mod1_").value%></td>
	</tr>
	
<% 
irowcolor = irowcolor + 1
orders1.movenext
loop
else
%>
</form>
<tr>
	<td class="auto-style1">There are no active orders at this time.</td>
</tr>
<% end if %>
</table>
	
</body>

</html>
 
Hi

When Lyndon asked you
Lyndon said:
Is id3 a valid variable?
he certailnly meant that "Is id3 a valid [red]JavaScript[/red] variable?". Well, seems it is not.

Maybe this :
Code:
onChange="document.form[highlight]<%=id3 %>[/highlight].submit()"
( Just a guess, as I have no idea about ASP. )

Feherke.
feherke.ga
 
I understand his question now.

No it is not a valid js variable. I have tried your example in the beginning but JS does not play well with asp tags at all.

So how do I make my asp variable into a js variable?
 
Hi

Bambamn007 said:
So how do I make my asp variable into a js variable?
Just generate JavaScript code where you output the ASP variable's value on the JavaScript assignment's right hand side :
Code:
<script>
var jsvar = '<%=aspvar %>'
</script>

Note that the above will fail if aspvar contains multiline string or string with escape sequences which will interfere with the JavaScript string literal syntax. Also you should make sure that characters with special meaning in HTML get transformed into character entities. No idea how. You will need to consult the ASP documentation on escaping and quoting. But for numeric values the above code should work fine. However this was just an answer to your question, the code itself is nothing better than the earlier one ( 27 Jun 14 9:10 ).


Feherke.
feherke.ga
 
I now have the form name being dynamic with the id. thanks to everyone.

However, this did not stop the issue of the onchange sending the values for each record. I thought making each record having a different form name would solve this, but it did not.

I am now unsure where to go. Could be asp, could be js, could be html.... I just don't know.

But thanks to everyone who gave me advice.
 
PROBLEM SOLVED!

Here is the solution. One must pay attention where things lie on a page that contains html, asp, and JS.

I had the clode form tag </form> outside of the loop where I was getting records from the database. Once the tag was moved into the loop, viola!

Thanks so much to everyone for their patience and guidance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top