SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    How to unset something that is going to be sent with the form?

    On this page if you click the Custom... option in the dropdown menu at the top, a text input box appears. Let's say the user inputs a number but then changes their mind, leaves the value there and chooses something else in the dropdown. The input box goes away, but the value for it is still set and the form will pass it on in the URL (I'm using GET). This is the javascript I'm using at the moment:
    Code:
    window.onload = function() {
          var x = document.getElementById('thumbs');
            x.onchange = function() {
              if (x.value == 'custom') {
                document.getElementById('customthumbsinput').style.display='inline';
              }
              else {
                document.getElementById('customthumbsinput').style.display='none';
              }
          }
    How can I stop this from happening?

    Also, I suspect there is something horribly wrong with that javascript because Opera won't display anything unless JS is turned off and IE takes an eternity to load it, and not because the server is slow or anything.

    Cheers,

    Rafael

  2. #2
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Within the else {} part of your javascript, set the value of that field back to blank:
    document.getElementById('customthumbsinput').value = "";

    But a better solution would probably be to have your back-end form processing just ignore that field if the dropdown is not on Custom.

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, and about your page loading slowly and being broken, your external js and css pages are not loading, and the server is getting stuck in a loop trying to load them. Comment all those out and your page should work better. Then find them a better place to live.
    <!--
    <link rel="stylesheet" href="js/lightbox.css" type="text/css" media="screen" />
    <script src="js/prototype.js" type="text/javascript"></script>
    <script src="js/scriptaculous.js?load=effects" type="text/javascript"></script>
    <script src="js/lightbox.js" type="text/javascript"></script>
    -->

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,803
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You could use:

    document.getElementById('customthumbsinput').disabled = true;

    Any disabled fields in the form will not get passed when the form is submitted.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks felgall, that's great.

    dwyw, I'd rather not sort it out on the server side because I'm using GET and customthumbsinput would still show up in the query string. Even when I do document.getElementById('customthumbsinput').value = ""; it's just an empty query string.

    What do you mean, find them a better place to live? I need those. And I don't see what loop the server is getting into nor what the problem with loading them should be., especially the stylesheet.


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
  •