...

View Full Version : Modifying data entered in a form field?



afranka
07-16-2003, 12:05 PM
Hi,

I have a date field in a form, which I can validate using javascript, but I have to be able to allow users to enter 'tbc' into this field.

I can check for 'tbc' when validating the form, but is there a way i can replace 'tbc' for an actual date before the form gets submitted?

i.e. can I use javascript to replace a value in a form field once a user has clicked submit?

Thanks very much,
al.

Kor
07-16-2003, 02:01 PM
yes, i believ you can. Simply change the value of the textfield in a javascript function

function change(){
document.forms[0].texfield_name.value = "your new value here";
return true;
}


in body, in your form tag

<form onsubmit="return change();">

i did not test, but i suppose it will works...

arnyinc
07-16-2003, 03:24 PM
Basically the same thing :)

<html>

<head>
<script language="javascript">
function change(der){
if(der.value=="tbc")
der.value="1/1/1990";
return true;
}
</script>
</head>
<body>
<form onsubmit="return change(this.myfield);">
<input type="text" name="myfield">
<input type="submit">
</form>
</body>
</html>

Kor
07-16-2003, 03:33 PM
the arnyinc script is complete, indeed. Now I can sense the ideea of the script (I did not understand at the very begiining why to change that).

I think that afranka wants to avoid submitting "four letters words" :-). In this case, you may have a list of those, and insert them in script

if(der.value=="flw1" || der.value=="flw2"|| der.value=="flw3")
der.value="beeeeep!LOL";

so

afranka
07-16-2003, 03:41 PM
Thanks very much for your help!!!

al.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum