SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2008
    Location
    Plano, TX
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    remove double quotes

    I'm trying to remove double quotes from a text field before the form gets submitted. I can't do it afterword, I don't know why, but everything i try just doesn't seem to work. so i'm trying to use javascript to do it before i submit but i don't know how. the form field i'm trying to do it in is named keyword. if you know how please let me know.
    Last edited by machutta; Oct 27, 2008 at 10:56.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Code html4strict:
    <form id="myForm">
        <p>Keyword: <input type="text" name="keyword"></p>
    </form>

    Code javascript:
    var form = document.getElementById('myForm');
    form.onsubmit = validateForm;
     
    function validateForm() {
        var keyword = this.elements.keyword;
        var global = 'g';
        keyword.value = keyword.value.replace('"', '', global);
    }

    If you put the script at the bottom of the page, as you're supposed to do as a best practice to speed up your web site, then you'll be all set.

    If you run scripts from the head then you'll need some kind of window.onload technique to delay the first couple of lines until the page content is available to with with.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •