Change Form Field Value Prior to submit

R

r0adhog

I am trying to do some form validation.
Is there a way with vb script to change the value of a field
on a form prior to submit.
 
R

Ray at

You could do this with client-side script, if you like. But, if you're
going to change it and you know what you're going to change it to, why not
do it in the ASP code that processes the form submission? Can you be a
little more specific about what you're trying to do?

Ray at work
 
R

r0adhog

Ray/Curt,

I guess I could do it after the submit, was looking to do something like
If x = "true" then
document.MyForm.all("FieldName").value =
CleanedUp(document.MyForm.all("FieldName").value)
document.MyForm.summit()
End If

Will that work?

rh
 
R

Ray at

Well, this would be the client-side approach, not the ASP approach. As Curt
suggested, you should not use VBScript for client side scripting. Try
something like:

<script type="text/javascript">
function myFunction(f) {
// What is x?
var x = true;
var v = f.FieldName.value
if(x) {f.FieldName.value=CleanedUp(v); }
return true;
}

function CleanedUp(s) {
return 'what should this be?';
}
</script>


<form onsubmit="return myFunction(this);">


Again, what are you trying to do? You're not doing this to deal with
apostrophes or anything, I hope, are you?

Ray at work
 
D

Dave Anderson

r0adhog said:
I guess I could do it after the submit, was looking to do something
like If x = "true" then
document.MyForm.all("FieldName").value =
CleanedUp(document.MyForm.all("FieldName").value)
document.MyForm.summit()
End If

Will that work?

It pains me to say, "probably" (except for the misspelled submit() method),
but it certainly depends on intercepting the submission.

It pains me for three reasons: (1) VBScript on the client, (2) the use of
..all, and (3) referencing a collection with parentheses instead of brackets.
Internet Explorer lets you get away with all three, but I don't consider
that a good thing.

Generally speaking, form element references ought to look like this:

document.MyForm.elements["FieldName"]

If you don't use funky characters for naming your fields (and don't collide
with the FORM element's property/method namespace, you can get away with
this:

document.MyForm.FieldName

Examples that require the former:

<INPUT NAME="Address(2)"> **
<INPUT NAME="submit"> ***

I object to VBScript on the client for religious reasons, FWIW.



**I've actually seen this!!
***Probably one of the most common newbie errors


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Ray at

Dave Anderson said:
I object to VBScript on the client for religious reasons, FWIW.

This topic doesn't seem to be addressed in my current reading, the Complete
Idiot's Guide to Understanding Judaism, so I guess it must be some other
religion.

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top