PDA

View Full Version : If box empty use other input area



motormichael12
10-14-2006, 10:20 PM
Can anyone give me a script that makes it so when using a form, if a textbox is emtpy, it uses the data from another hidden textbox?

I am not very good at scripting things for vars and ifs... so please help

something like this, even though it is wrong it is for example... pretend it is all in a form tag



<textarea name="text1"></textarea>
<div id="text1data">text1's data</div>

<script>
if "text1" value=empty
insert image into "text1data" div
</script>


then the box would use the value specified for text2 if the box "text1" is emtpy.

*CODE IN THIS POST EDITED AFTER POST NUMBER 6*

motormichael12
10-14-2006, 10:20 PM
lol i cant do good scripts like that so it might be confusing... sorry

tech_support
10-14-2006, 10:40 PM
<script language="JavaScript" type="text/javascript">

function checkValues() {

formname = 'yourformname'
fieldname = 'yourfieldname'
fieldname2 = 'yourhiddenfield'
if (document.forms[formname].elements[fieldname].value=="") {

document.forms[formname].elements[fieldname].value = document.forms[formname].elements[fieldname2].value

}
else {
return;
}
}
</script>


Untested.

motormichael12
10-14-2006, 10:57 PM
Couldn't get that to work.

tech_support
10-14-2006, 11:02 PM
Did you enter the form name, field name and the hidden field name?

motormichael12
10-14-2006, 11:52 PM
Canceled this code.

motormichael12
10-15-2006, 12:06 AM
Code in 1st post now edited to meet the material I just specified

motormichael12
10-15-2006, 12:28 AM
Never mind, I don't need it... I would have to put it in every area that might have the signature, and I don't want to do that... too much work.