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

ssi preventing JScript 1

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hows it going? the Else statment doesn't work, any ideas? all other ElseIfs validate, and the last Elses has a Javascript call in it to submit the form, the JS don't initiate, it would if i put the page.asp url into the bowser and press enter, then the js script posts the form, but as a ssi or directly placed into the asp page it doesn't work? any ideas why?

Code:
<%	
If gstrProfessionId = "4" Then 
%>
<!--#include file="registrationContinued2.asp"-->
<% 
ElseIf gstrProfessionId = "11" Then  
%>
<!--#include file="registrationindustry2.asp"-->
<% 
ElseIf gstrProfessionId = "1" Then  
%>
<!--#include file="registrationnurse2.asp"-->
<%
ElseIf gstrProfessionId = "3" Then  
%>
<!--#include file="registrationpharamist2.asp"-->
<% 
Else
'   also tried code below as an include like above without any luck
%>

<html><head>
<script type="text/javascript">
function setFocus(){
document.registrationFrm.submit();
}
window.onload = setFocus;
</script>
</head><body>
<form action="validate.asp" method="POST" name="registrationFrm">
<% 
For Each thing In Request.Form 
Response.Write "<input type=""hidden"" name=""" & thing & """ value=""" & Request.Form(thing) & """>" & vbCrLf 
Next 
%>
<p align="center">&nbsp;<p align="center">
Your information has been validated, please click the button below to begin the survey.<p align="center">
<input type="submit" value="Submit" />

</form>
</body>
</html>


<%
End If
%>
 
Do you mean that the javascript still outputs but just doesn't fire when you include it in the ASP page, or that none of that HTML shows up at all?

-T

barcode_1.gif
 
Tarwn, that exactly correct, like there is an asp versus JS timming issue

Sheco,

this is the view source:
Code:
<html><head>
<script>
document.forms['registrationFrm'].submit();
</script>
</head><body>
<form action="validate.asp" name="registrationFrm" method='POST'>

<input type="hidden" name="gstrSurveyId" value="374">
<input type="hidden" name="frmFirstName" value="asdfasdf">
<input type="hidden" name="frmCity" value="asdfasdf">
<input type="hidden" name="frmPostalCode" value="R4R4R4">
<input type="hidden" name="frmEmail" value="asdfasdf@f6666666f4.cv">
<input type="hidden" name="frmLastName" value="asdfasdf">
<input type="hidden" name="frmProvince" value="9">
<input type="hidden" name="frmPhone" value="222-555-8888">
<input type="hidden" name="frmOptContestRules" value="yes">
<input type="hidden" name="surveyid" value="374">
<input type="hidden" name="frmCountry" value="CANADA">
<input type="hidden" name="frmProfession" value="21">
<input type="hidden" name="frmOptJoinProgram" value="yes">
<input type="hidden" name="frmFax" value="">
<input type="hidden" name="frmAddress1" value="asdfasdf">
<input type="hidden" name="frmGender" value="Male">
<input type="hidden" name="frmPassword" value="66666">
<input type="hidden" name="frmPasswordConfirm" value="66666">
<input type="hidden" name="frmLanguage" value="english">
<input type="hidden" name="frmCommunication" value="email">

<p align="center"><p align="center">

Your information has been validated, please click the button below to begin the survey.<p align="center">

<input type="submit" name="submit" value="submit" />

</form>
</body></html>
 
... maybe call the form submit from the body's onLoad() event

Is this the same problem discussed on the JavaScript forum here: thread216-1219464

 
This

Code:
<script>
document.forms['registrationFrm'].submit();
</script>

needs to be AFTER the </form> tag. If you need a short delay, you could use setTimeout. Set it for half a second to one second, and see if that takes care of things.

The Javascript is executed on the client side, so all the server-side code has been processed by the time the client's browser encounters the JS (barring any Response.Flush statements).

Lee
 
Sheco, i've tried that already without any luck

trollacious, i have also tried that already what happens is that there is no JS error until the function instantiates
Code:
</form>

<script>
window.onload = function(){
setTimeout("damnDelay()", 2000); //2 secs
}

function damnDelay() {
document.forms['registrationFrm22'].submit();
}
</script>

in the above case the IE error says:
object does not support the property or method and points to this line:
document.forms['registrationFrm22'].submit();


/////////// any suggestions......
 
//could this be happening because the page is under a SSL ?
 
i have even taken the delay a step further and did this:

Code:
</head><body onload="delayTim()">
<form action="b4validate.asp" name="registrationFrm22" method="GET">
<% 
For Each thing In Request.Form 
Response.Write "<input type=""hidden"" name=""" & thing & """ value=""" & Request.Form(thing) & """>" & vbCrLf 
Next 
%>
<p align="center"><p align="center">

Your information has been validated, please click the button below to begin the survey.<p align="center">

<input type="submit" name="submit" value="submit" id="submit" />

</form>
<script>
function delayTim(){
setTimeout("damnDelay()", 3000); //2 secs
}

function damnDelay() {
document.forms['registrationFrm'].submit();
}
</script>
 
The core problm to begin with is that when you leave your javascript loose in the code (not inside a function, etc) it executes as soon as the browser gets to it. The reason this is an issue is if your referencing objects (in this casea form) that have not been rendered yet, than the browser canot reference them.

If you call the submission from the onLoad then there is no need to add a timeout as well. The onLoad doesn't fire until everything on the page has been rendered. This ought to work just fine:
Code:
<script>
window.onload = damndelay

function damnDelay() {
   document.forms[0].submit();
}
</script>

-T

barcode_1.gif
 
do you have access to a server with asp enabled?

try this out for yourself, it does not work no matter how the JS is writtenj and where it lies i the html:

page1.asp
Code:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="page2.asp">

  <select name="frmProfession">
    <option value="1">1</option>
	    <option value="2">2</option>
		    <option value="3">3</option>
			    <option value="4">4</option>
  </select>
  
  <input type="submit" name="Submit" value="Submit">

</form>
</body>
</html>


page2.asp
Code:
<%
gstrProfessionId = Request.Form("frmProfession")

select case gstrProfessionId
case "1"

response.write "do nothing"

case "2"

response.write "do nothing"

case "3"

response.write "do nothing"

case Else
%>

<html>
<head>
</head>
<body>

<form action="validate.asp" name="registrationFrm" method="POST">

<input type="hidden" name="asdf" value="ewrty">

<input type="submit" name="submit" value="submit">
</form>
<script type="text/javascript"> 
document.registrationFrm.submit(); 
</script> 
</body>
</html>

<% 
end select
 %>
 
Try changing the name attribute of your submit button to something else, like submitbutton. Naming elements the same thing as a form method can cause problems. You have 2 objects called submit, one is a built-in method and then you declare an element name with the same value. The one being referenced is the element name submit, not the method submit().

Lee
 
Your first example doesn't have the submit button named submit, but both your subsequent ones do have that. I missed it when looking over your code earlier.

Lee
 
Try changing the name attribute of your submit button to something else, like submitbutton. Naming elements the same thing as a form method can cause problems. You have 2 objects called submit, one is a built-in method and then you declare an element name with the same value. The one being referenced is the element name submit, not the method submit().

changing the name worked like a charm, guess submit is a reserved word in JS, Thanks trollacious, you made all the difference! cheers
 
No, submit isn't a reserved word in Javascript. You had a form method/function named submit and a form property/element named submit. If you have 2 objects named the same thing at the same level, whether property, method/function, or whatever, you can end up with problems. I'd guess that the form element named submit received precedence because it was created last and the reference to that overwrote the reference to the method you were trying to call.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top