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

Hiding the value in an html textbox 1

Status
Not open for further replies.

Katie6

Programmer
Jun 12, 2007
58
GB
Hi there,

I've got a form with three fields called:

- surname
- ID
- email address

The user enters the details into one or more of the fields, clicks submit, and this pulls all the data about the person/people searched for.

The user will not always know all of the information, so occasionally, a field will be left blank. However, if no information is entered, I need the default values of the text boxes to be:

- surname
- ID
- email_address

At the moment my form works fine, because I have set a value for each textbox. However, my form looks messy because these values appear in the form.

I would like all of the form fields to appear blank until someone enters the details, but I would like there to be a hidden default value. To acheive this, I was thinking I would need some javascript that says, for example:

if the email address field is left blank, let the value of that field be equal to email_address when the submit button is pressed.

The result I'm hoping for is that the form fields will be blank to the user, but, when the submit button is pressed, any blank fields will be given a value of surname, ID or email_address (depending on the field name).


Would anyone be able to help me with this? Any other ways of achieving the same effect would also be much appreciated.

Many thanks,

Katie
 
Hi

If you ask me, it is more than strange request. And anyway, you should deal with this on server side.
Code:
<html>
<head>
<title></title>
<script>
function check(what)
{
  if (!what.surname.value) what.surname.value='surname'
  if (!what.ID.value) what.ID.value='ID'
  if (!what.email_address.value) what.email_address.value='email_address'
}
</script>
<body>
<form action="#" onsubmit="check(this)">
<input type="text" name="surname">
<input type="text" name="ID">
<input type="text" name="email_address">
<input type="submit">
</form>
</body>
</html>

Feherke.
 
I agree with Feherke. This sort of thing should be done server-side in case the user has JS disabled. Sure - you can do it both client- and server-side, but don't rely solely on client-side.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for your advice - I have tried doing it on the server side but it's been tricky. I just wondered if there was another way. I'll keep plodding on with the SAS code instead! Thanks very much once again - you've saved me wasting lots of time trying to think of an alternative solution :)

Katie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top