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!

auto submit page possible? 1

Status
Not open for further replies.

puterdude

Technical User
Apr 13, 2001
51
US
Hi,

This may sound stupid, but what the heck.
I have an asp page that inserts a record into one file. Because it creates a key (autoincrement field), I need that key to keep another table in sync. Since the key doesn't exist until it is commited, I cant do both at once.

question:
Can I have the insert page complete, go to a new page (now that it has the key, and have that page automatically submit itself so I can load that key into the record of the second table?

It may look strange to the user to see a page load and go away, and a new page load, but I don't want them to have to press submit twice.

Is this too weird? :)

Thanks,

Puterdude
 
Yes, that's no problem --

Just redirect the page to the new page (along with the key value -- possibly via querystring) and then on that page, don't put any html -- only asp --

and do what you need to do -- just remember not to put any html headers, and the user won't even know that it happened...

Once you are done there, just redirect to another page and get along with your business.

:)
Paul Prewett
 
Do what I need to do??

Do you mean put an insert behavior on the page and then at the bottom a redirect?

Not sure the sequence of what you are saying.

thanks,
 
Why not just run a second sql and insert the key field into the second table. There is no reason to open another page.
do something like this.

sql = "INSERT INTO Table1........)"
RS.Open sql, conn, 3, 3

' Run sqlID to get current record number
SqlID = "SELECT max(table1.ID) AS ID FROM cladsp"
RS.Open SqlID, conn, 3, 3

sql2 = "INSERT INTO Table2 ID_Table1........)"
RS.Open sql2, conn, 3, 3

Then everything is done

Mark
 
Mark,

Thanks. I do have a question about how all this would work.

If the table is being hit by two people at the same time would it ever give the wrong Max(table.id) to someone?

puterdude
 
If you use a lockType of 2 (adLockPessimistic), you will never get a "dirty read" --

No other processes will be allowed to touch the table while another is doing something with it.
 
Cool. I never heard of that.
Can you tell me where to put that in my code and the correct syntax.

Also, do you guys do programming for hire? If not, can you point me to a web site where programmers lurk. ;)

I have 1 screen which I need done and it is too hard for my humble newbie skills, but should be a piece of cake for someone who knows what they are doing.

Thanks,

Puterdude
 
recordset.lockType = 2

or if you have included the adovbs.inc include file, then you can just say:
recordset.lockType = adLockBatchPessimistic

The statement must go somewhere after this:
set recordset = server.createobject("ADODB.Recordset")

and before this:

recordset.open

Here's a FAQ on the three most important recordset properties. faq333-618

Not sure about "for-hire" folks -- but if you have specific problems, then post them here, and work them out. It'd be better for ya that way, anyway. ;-)

good luck!
 
Thanks for the help. It's not that I don't want to learn, just that this is so new to me that I have trouble understanding some of the help given.

The one screen I mentioned has 15 fields I would like to check against a separate table, prior to updating the record. Simple validation won't due. I want the user to be bounced back to the form if any values they enter are incorrect. I would also like to tell them which items(s) are wrong by highlighting them or something.
It was suggested I use an array, but I have no idea how to start this or finish it. I can usually hack it out if I can see an example of code where it was done somewhere else, but I cant find any examples.

I thought it would be an easy programming task if you know what you are doing. I use a different language for my software and I could do it easily in that, just dont know asp at all.

Puterdude
 
Ok -- how many columns and rows are in the table that you need to check against???
 
You see! Now there your go. Columns and rows is a totally different way of looking at things to me. I'm used to fields and records etc.

Columns and rows in the table to check against? If columns are fields, then there are 8 columns and 12741 rows (records).

Is that what you are asking?
 
Yea, that's what I'm asking. But I think that's a little much to read into a client side array --

You might want to look into Swany's FAQ's over in the vbscript section about Remote Scripting -- With it, you can make a round trip to the server without submitting -- it's like client/server script. I haven't personally used it before, though. :-(
 
Can you think of any other ways I might do this? Is it possible using javascript?

I found out from my host that they do not allow remote scripting on the server. :(

Thanks,

Puterdude
 
The only other way I can think of off the top of my head without submitting the form would be to read all the information into a client side array -- and I just don't think I'd go that route -- way to much information to be sitting in memory --

I would just make a round trip to the server each time and check the values -- it's a simple enough procedure -- and it happens fairly quickly -- just the slightest flicker of the screen since most all the information is already cached on the client anyway --

Put an onChange or onBlur event on each of the elements that point to a function that will submit the form, and then check all the values coming back into the page -- persist them possibly in another form at the bottom of the page, and have that be the one that actually gets "submitted" when the user is ready to hit the button --

I think it would be the best way --

good luck :)
Paul Prewett
 
Paul,

Do you have or know where to point me for an example?

Thanks
 
Ok, here goes a shot at a very simple example:

I have a table called 'emp' that has a field in it called 'id', which I want to check against when a user enters a value in the text field.

In this example, the page will have two forms -- one that submits to itself (where the user enters the info), and one that leads to the following page (once they enter valid info). If valid information is entered, then that information will be entered into the hidden field of the second form, and that's the one that has the submit button, which will carry the user to the next page --

A value will be entered into the hidden field iff a valid entry has been made, and then before we allow the user to submit the form, we will check to see if that hidden field has been assigned a value. If so, then we'll let them pass. If not, then we won't --

Code:
<%@language=vbscript%>
<%option explicit%>
<%
dim con, rs
dim value
value = request.form(&quot;value&quot;)

'THIS WILL CHECK TO MAKE SURE IT'S NOT THE FIRST LOAD OF THE PAGE
'IF IT'S NOT, THEN WE'LL MAKE THE RECORDSET AND CHECK VALUES
if value <> &quot;&quot; then
	set con = server.createObject (&quot;adodb.connection&quot;)
	set rs = server.createobject (&quot;adodb.recordset&quot;)
	con.open (mydsn)
	'SELECT FROM THE TABLE, ALL RECORDS WHERE ID = THE ENTERED VALUE
	rs.open &quot;SELECT * FROM emp WHERE id=&quot; & cint(value), con
end if
%>
<html>
<head>
<title>testing</title>
<script>

	//THIS IS THE FUNCTION THAT WILL SUBMIT THE FORM onBlur AND THEN THE
	//  SERVER SIDE CODE ABOVE WILL CHECK FOR THE VALUE IN THE DATABASE
  	function checkValue(){
  		document.theForm.submit();
  	}
  	
  	//THIS IS THE FUNCTION THAT WILL VALIDATE THAT A VALID VALUE HAS,
  	//  IN FACT BEEN ENTERED -- OTHERWISE, IT WILL DISALLOW THE USER
  	//  TO SUBMIT THE FORM AND CONTINUE
  	function validateMe(){
  		if (document.thatForm.value==''){
  			alert('You must enter a valid value before\nyou are allowed to continue!');
  			return false;
  		}
  		return true;
  	}
</script>
</head>
<body>

<%
'HERE, WE ARE CHECKING IF WE CREATED THE RECORDSET OBJECT
'  IF WE HAVE, THEN WE RUN A CHECK TO SEE IF IT'S EMPTY
'  IF IT IS EMPTY, THEN WE CAN ASSUME THAT THE ID DID NOT EXIST IN THE DATABASE
'  IF IT IS NOT EMPTY, THEN WE CAN ASSUME THAT IT DID EXIST
if isobject(rs) then
	if (rs.eof and rs.bof) then
		response.write(&quot;<script>&quot; & vbcr)
		response.write(&quot;alert('&quot; & &quot;The value you entered is not valid&quot; & &quot;');&quot;)
		response.write(&quot;</script>&quot; & vbcr)
		value = &quot;&quot;
		set rs = nothing 'DESTROY THE OBJECTS
		set con = nothing
	end if
end if
%>

<form name=theForm action=thisPage.asp method=post>
<input type=text name=value onBlur=&quot;checkValue();&quot;
</form>
<form name=thatForm action=nextPage.asp method=post onSubmit=&quot;return validateMe();&quot;>
<input type=hidden name=value value=<%=value%>
<input type=submit value=submit>
</form>

</body>
</html>

I hope this helps :)
Paul Prewett
 
Paul,

Thanks a lot. I understand most of it. I'll have to try it to see how it will work.
I have 15 fields to check, unfortunately, all in the same db. So, if records are returned for field1, it is possible gthat field2 is incorrect, but still returns records.
Would you suggest 15 runs at it? With 15 hidden fields?

Thanks again.

Puterdude
 
Fifteen fields, eh?

Ever think about doing it with list boxes??? I mean, it's getting a little out of hand, don't ya think?

I guess if I had to validate fifteen fields, then I would probably do it via a button --

Fifteen fields in form1 -- fifteen hidden fields in form 2

with a &quot;check values&quot; button on the bottom -- the submit button would be there, too, but until the checkValues() function had successfully checked and validated all my values, it would have an attribute of 'disabled = true'

Then, when a user clicked the check values button, I would run a routine very similar to the one above, and just check all the values at once -- submitting the form to itself, creating a recordset with multiple WHERE this OR that OR that type statements in it to catch all the different values, and then go through and check them one by one -- throwing an alert box if any weren't found --

Then, the last line of the function might be:
document.form2.submitButton.disabled = false;

or better yet --

document.form2.submit();

That second way, submitting the form for them, would alleviate the ugliness of two buttons, and make it appear as if they are just working on one form, when in actuality, it was two all along --

 
Thanks,

Yes, it is getting way more complicated than my newbie mind can get around. Your suggestion sounds doable. I don't know if list boxes would do it. 15 list boxes of 12000 possible values. Ugly and scary. I don't even know the limits on list boxes, but I would think loading them would be a bear.

I will see if I can implement your suggestions. I'm a little over my head here.

Thanks to everyone who helped.

Puterdude

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top