|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm using an onClick event to populate a text box with an x. Is there a way to use a separate or the same script to clear the box (or replace with a space) the next time the text box is clicked on? Thanks in advance.
Bob |
|
#2
|
||||
|
||||
|
document.formname.fieldname.value="" is the bit you probably already know - we would need to see your code to see the best way to implement it.
does the value change with an onclick on the text box ? or elsewhere - if elsewhere you can then call the clearing code above with an onfocus() or onclick() event in the input field itself. ------------------ Simon Wheeler FirePages -DHTML/PHP/MySQL |
|
#3
|
|||
|
|||
|
I'm including a couple of the fields from the form in question. Basically, what I have is a tool for my company that allows someone to fill out the form, print and email it for a price quote.
As there can be multiple service points for each order, I went with an array to capture the data. I couldn't use check boxes or drop lists because neither could pass a value for the unchecked/unselected items. Consequently, upon submission, the data input was not accurate because everything shifted to fill the voids. So, I decided to do a text box/check box and give the sales people back a measure of the functionality of the check boxes. The onClick I used has been modified from a script that opened an alert window - I just futzed with it until it works. So, I don't know for certain if it's the best solution ot not. I really appreciate your efforts to date. Thanks. Bob ****************************************** <?$i=0?> <form method="post" name="salesForm" action="salesForm.phtml" onSubmit="return CheckForm();"> <?while ($i< 2):?> Location <?echo ($i+1)?>: <input type="text" size="1" name="dldckDS1[]" onClick="document.salesForm.x;value='x';return true;" value="<?echo $dldckDS1[$i]?>"> DS-1 (T1) <input type="text" size="1" name="dldckDS3[]" onClick="document.salesForm.x;value='x';return true;" value="<?echo $dldckDS3[$i]?>"> DS-3 (T3) <p> <?$i++?> <?endwhile?> </form> |
|
#4
|
||||
|
||||
|
not sure why you can not use a checkbox? - but anyway the code below works.
You will have to use this format as you are generating inputs via a loop, just echo the name of the field & the value of check() and it should work for a 100 textboxes. <html> <head> <script> function check(fvar){ var formval='document.formname.'+fvar+'.value'; (!eval(formval))?newval='document.formname.'+fvar+'.value="x"' :newval='document.formname.'+fvar+'.value=""'; eval(newval); } </script> </head> <style> </style> <body bgcolor="#ffffff"> <form name=formname> <input type=text name=fname onclick="check('fname')"> </form> </body> </html> PS: remember that in Netscape - you have to address a form in a div or layer explicitly - ie: document.formname.name.value in a <div id="thisdiv"> becomes document.thisdiv.document.formname.name.value Hope this helps Regards, Simon. ------------------ Simon Wheeler FirePages -DHTML/PHP/MySQL |
|
#5
|
|||
|
|||
|
Thanks. This looks great. I wish I could use a checkbox - tried to initially but my data went nuts after the submit and lost with elements were not checked. What happened was:
Before submit: ck1 ck2 1st record x 2nd record x After submit: ck1 ck2 1st record x x 2nd record I tried all sorts of things but could never figure out how to give an un-selected checkbox a value in an array it was okay as a single record but would no work in an array - selection lists were the same. I'll keep looking long term because I know there's an answer to it but will have to go with this to make deadline. Thank you, thank you for all your help. Bob |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Clearing a form field once it's been populated by an onClick? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|