Results 1 to 6 of 6

Thread: onChange do doc.write

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default onChange do doc.write

    Ok, just to put it out there. I am awful at javascript... seriously...
    I have this form where users can create a new page...
    This is where the user selects what type of page he would like to create.

    HTML Code:
    <p>
    <label for="pType">Page Type:</label>
    <select name="pType">
    <option value="HTML">HTML</option>
    <option value="PHP">PHP</option>
    </select>
    </p>
    I would like to have it so when the user selects HTML it adds .html where .ext is:
    HTML Code:
    <p>
    <label for="pName">Page Name:</label>
    <input type="text" name="pName" />.ext
    </p>
    If user selects PHP then it adds .php to the same place.

    I don't know how todo this at all as I mentioned at top...
    I haven't used javascript in a long time, like 5 months, and I didn't even really know it then...
    Thanks to all who help!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    <div id="ext">.ext</div>
    onChange="document.getElementByID('ext').innerHTML = '.php';"
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    k thnx i'll try it out

  4. #4
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    I entered the code like this:
    Code:
    <p>
    <label for="pType">Page Type:</label>
    <select name="pType">
    <option value="HTML" onChange="document.getElementByID('ext').innerHTML = '.html;">HTML</option>
    <option value="PHP" onChange="document.getElementByID('ext').innerHTML = '.php';">PHP</option>
    </select>
    </p>
    <p>
    <label for="pName">Page Name:</label>
    <input type="text" name="pName" /><div id="ext"></div>
    
    </p>
    It didn't work... I don't think i entered it right though...

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

    Default

    It's a little bit different with select boxes. Changes are highlighted.

    Code:
    <p>
    <label for="pType">Page Type:</label>
    <select name="pType" onchange="document.getElementById('ext').innerHTML = this.options[this.selectedIndex].value">
    <option value="HTML">HTML</option>
    <option value="PHP">PHP</option>
    </select>
    </p>
    <p>
    <label for="pName">Page Name:</label>
    <input type="text" name="pName" /><div id="ext"></div>
    
    </p>
    Last edited by tech_support; 10-02-2007 at 01:44 AM. Reason: forgot about the select box
    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
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Its still doesn't work..
    I tried it in firefox and IE 7 and it doesn't work...
    I mean it would make perfect sense that it would work after that little fix... but Idk why... maybe my computer is deciding not to do that

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
  •