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

Mixing Javascript with ASP?

Status
Not open for further replies.

d1004

Programmer
May 9, 2002
78
0
0
US
I created a function using Javascript to check whether the users have entered their alias with the following code:

function Verify()
{
if (document.frmProcess1.Alias.value = "")

alert ("Please enter your alias!!!");
}

That mean that in my form I need to put name = "frmProcess1"
When I do that, I can't use Request.Form("Alias") on another page because it confuses what form to choose.
Here is my code for the form:
<form action=&quot;SetupPassword3.asp&quot; name&quot;frmProcess1&quot; method=&quot;post&quot; onSubmit = &quot;Verify()&quot;>
<table border = 0>
<tr>
<td> Alias: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input type=&quot;text&quot; name = &quot;Alias&quot; size = &quot;25&quot;></td>
<td><input type = &quot;Submit&quot; value=&quot;Search&quot;>
</tr>
</table>
</form>

I hope what I am saying make sense. Thank you!!!
d1004
 
I'm not exactly sure what the problem is, but change your variable names to something a little more abstract.

Change:
<input type=&quot;text&quot; name = &quot;Alias&quot; size = &quot;25&quot;>

To:
<input type=&quot;text&quot; name = &quot;tbAlias&quot; size = &quot;25&quot;>

If the problem is what I think it might be. Then you are using a reserved word for a variable.

Kris
 
When I do that, I can't use Request.Form(&quot;Alias&quot;) on another page because it confuses what form to choose
so name it something else.

I'm a little confused here. what is confusing about Requesting the name of the field that was passed A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Well, I was just guessing at a solution to your problem.

But in general it is a bad idea to use a single complete word when referencing &quot;variables&quot;.
You run the risk of using a reserved word that the complier will think you meant something else. You could learn all the reserved words, but why bother.

That is one reason most people use prefix naming conventions with their variable names.

Kris
 
Hi krisbrixon, I'm glad to see you passing the reference to naming conventions and reserved word issues on. that seems to be getting to be more and more a issue as many start to not follow coding conventions set for very good reasons.
example
txt for textbox's txtName
lbl for labels lblName
frm for forms frmGuestBook

[thumbsup2]
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
I think your problem is not on the name of the variable, it's on your JavaScript code, it will be wise if you use this on your form:
<form action=&quot;SetupPassword3.asp&quot; name&quot;frmProcess1&quot; method=&quot;post&quot; onSubmit = &quot;return Verify();&quot;>

and in your function &quot;Verify&quot; code always use a
return (true); or a return (false); if you really want to submit or cancel the information
 
Also might help to put an = sign between name and &quot;frmprocess1&quot;.
Code:
<form action=&quot;SetupPassword3.asp&quot; name&quot;frmProcess1&quot; method=&quot;post&quot; onSubmit = &quot;return Verify();&quot;>

Concerning form confusion: The web server will never get confused as to which form to pull information from. When a form is submitted only the data in that form (and no other) will be submitted. So when you are getting values out of the request object you can only get them out of the exact form that was submitted, even if there wer 5 other forms on the page.
If you change the name of an input field you can simply change the name in the Request.Form(&quot;&quot;) to match it.

-tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
oops, i guess I could have corrected that :p
Code:
<form action=&quot;SetupPassword3.asp&quot; name
=
Code:
&quot;frmProcess1&quot; method=&quot;post&quot; onSubmit = &quot;return Verify();&quot;>
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
In addition to Tarwn's correction, you should also change
Code:
if (document.frmProcess1.Alias.value = &quot;&quot;)
To
Code:
if (document.frmProcess1.Alias.value == &quot;&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top