By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

Form Question

P: n/a
I use forms where City and State names have to be entered, entry's that
have two names (example: New York) must have a lower dash inserted in
them
(example: New_York) before the form can be submitted, is there a way
this can be done with an onBlur event handler?
Thanks for any help, Joe

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Lee
Papajo said:

I use forms where City and State names have to be entered, entry's that
have two names (example: New York) must have a lower dash inserted in
them
(example: New_York) before the form can be submitted, is there a way
this can be done with an onBlur event handler?


It could be done using an event handler, but chances are that some
of your visitors will have Javascript disabled.

The only reliable solution is to fix your server side code so that
it doesn't matter.

Jul 23 '05 #2

P: n/a
Papajo wrote:
I use forms where City and State names have to be entered, entry's that
have two names (example: New York) must have a lower dash inserted in
them
(example: New_York) before the form can be submitted, is there a way
this can be done with an onBlur event handler?
Thanks for any help, Joe


As Lee says, there's no way of ensuring that this actually runs
before the form is submitted. But for the record, here's how to
do it:

<script type="text/javascript">
function spaceToScore(t){
var oVal = t.value;
var rexp = /^(\s+)?(.*\S)(\s+)?$/;
t.value = t.value.replace(rexp,'$2').replace(/\s+/g,'\_');
alert('Orig: \'' + oVal + '\'\nNow : \'' + t.value + '\'');
}
</script>

<form action="" onsubmit="
return spaceToScore(this.textInput);
">
<input type="text" name="textInput" value=" asdf asdf ">
<input type="submit">
</form>
--
Rob
Jul 23 '05 #3

P: n/a
you could use onSubmit which is executed before sending the data.

<form ... onSubmit="return lower_dash_function();">

lower_dash_function does
1. replace spaces in your input fields
2. returns true to submit the form

best way imho would probaly be to add the lower dash in the script that
performs the form action though

micha

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.