Results 1 to 8 of 8

Thread: If box empty use other input area

  1. #1
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default If box empty use other input area

    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

    Code:
    <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*
    Last edited by motormichael12; 10-15-2006 at 12:05 AM.

  2. #2
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    lol i cant do good scripts like that so it might be confusing... sorry

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Code:
    <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.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    Couldn't get that to work.

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Did you enter the form name, field name and the hidden field name?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    Canceled this code.
    Last edited by motormichael12; 10-22-2006 at 01:32 PM.

  7. #7
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    Code in 1st post now edited to meet the material I just specified

  8. #8
    Join Date
    Oct 2006
    Posts
    183
    Thanks
    0
    Thanked 11 Times in 11 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •