Form problem (originall from MR)

Discussion in 'Web Design and Development' started by EvanLugh, Mar 5, 2008.

Thread Status:
Not open for further replies.
  1. EvanLugh macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #1
    So i have this form;
    Code:
    <html>
    <title>Pfft</title>
    <body>
    <form id="dlForm" onsubmit="GoToUrl(this.id)">
    <select id="select-1">
      <option value="test/phpicalendar-0.9.5/rss/rss.php?cal=may&rssview=week">RSS</option>
      <option value="webcal://">iCal</option>
        <option value="">Outlook</option>
    </select>
    <select id="select-2">
      <option value="rss.php?cal=may&rssview=week">February 2008</option>
      <option value="test/phpicalendar-0.9.5/calendars/may.ics">March 2008</option>
        <option value="apr">April 2008</option>
      <option value="may">May 2008</option>
      <option value="jun">June 2008</option>
    
    </select>
    <input type="submit" value="Download" />
    </form>
    <script>
    var base = 'http://www.url.com/';
    var ext = '';
    function GoToUrl(id)
    {
      // identify by form id. Helpful if there's more than one form on page
      if (id == 'dlForm') {
        // get value attribute from first select tag
        s1 = document.getElementById('select-1').value;
        // get value attribute from second select tag
        s2 = document.getElementById('select-2').value;
        // send user to new url (for download)
        location.href = base + s1 +""+ s2 + ext;
        // use this line to test what URL will be.
    alert(base + s1 +""+ s2 + ext);
      }
    }
    </script>
    </body>
    </html>
    I have a few problems.
    Firstly, if it's grabbing the RSS feed, i don't want it to download the .ics because i want it to show the RSS, same with outlook (basicall there's only one s2 even though i need to put 3 formats.
    Secondly, mostly working fine on mac, but on windows it just redirects to the homepage instead of the same page, unless you enter the URL manually. On all browsers too, what's with that, I can't seen anything for that?

    All for now, thanks. If you don't understand what I mean, i'll make an image and upload it.

    Thankyou :eek: :)

    EDIT: If anyone wants to test to see what i'm on about, PM me and i'll send you a login username/password. thanks.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Your first question I don't quite follow, which is bad since I helped you with that code ;)

    The second question kind of sounds like on Windows it's getting directed to your base url (the base variable) without the other variables, though not sure why. I'll be able to look at it more after work.
     
  3. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #3
    Thanks angelwatt.
    Question 1: Example layout to explain..

    RSS Feb2008
    iCal March 2008
    Outlook April2008

    Say i want the RSS Feb2008. in the code there can only be 1 url. so say i have the rss feed url in the Feb2008 tags, that would be fine.
    But what if i want to download to iCal Feb2008? It would attempt downloading the same url as the rss feed.

    Let me know if you didn't get that, and yes all previous credit to angelwatt :rolleyes:
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    OK, here's an updated script to handle that (if I followed your explanation correctly). The actual urls are appearing as alerts since the links aren't real so you can comment out the alerts when ready and uncomment out the location.href lines.
    Code:
    <script type="text/javascript">
    var base = 'http://www.url.com/';
    var ext = '';
    function GoToUrl(id)
    {
      // identify by form id. Helpful if there's more than one form on page
      if (id == 'dlForm') {
        // get value attribute from first select tag
        s1 = document.getElementById('select-1').value;
        // get value attribute from second select tag
        s2 = document.getElementById('select-2').value;
        // send user to new url (for download)
        // check if it's the webcal one
        if (s1.indexOf('://') != -1) {
          //location.href = s1 +"www.url.com/"+ s2 + ext;
    alert(s1 + "www.url.com/"+ s2 + ext);
        }
        else {
          //location.href = base + s1 +""+ s2 + ext;
    alert(base + s1 +""+ s2 + ext);
        }
      }
    }
    </script>
    Also to maybe help with that Windows problem the following may help. The return false at the end should keep the user from switching pages, but it may possibly stop the download from occuring as well so you may want to try that later.
    HTML:
    <form id="dlForm" onsubmit="GoToUrl(this.id); return false;">
     
  5. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #5
    For the sake of other members; this is what i have sent to angelwatt.

     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    Seems to be working for me, more or less. When I tried leaving the default values with the RSS it came to a page with the RSS. When I tried the Webcal one it opened up iCal on my machine, though failed to connect to the actual file (is everything uploaded?). When I tried the Outlook I got a page saying there is no rss.php file, though says there is a document /rss?cal=may&rssview=week page (that link didn't work) and a rss.ics one (kind of worked).

    The alerts come up for me too, though you may want to move them in front of the location line as that may stop the alert code.

    Maybe you can elaborate on what's happening, and why it's wrong and how it should work. Like if something is missing in a URL. I haven't worked with webcal links before so not sure about their format.

    As a note, I've just been testing in Firefox.
     
  7. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #7
    Nope, unfortunatly still having problems.
    angelwatt:
    Code:
    http://[removed].com/dropdowntestC.html
    There's the script, see for yourself.
    This is the code I have:
    Code:
    <html>
    <title>Pfft</title>
    <body>
    <form id="dlForm" onsubmit="GoToUrl(this.id); return false;">
    <select id="select-1">
      <option value="test/phpicalendar-0.9.5/rss/rss.php?cal=may&rssview=week">RSS</option>
      <option value="webcal://">iCal</option>
        <option value="">Outlook</option>
    </select>
    <select id="select-2">
      <option value="rss.php?cal=may&rssview=week">February 2008</option>
      <option value="test/phpicalendar-0.9.5/calendars/may.ics">March 2008</option>
        <option value="apr">April 2008</option>
      <option value="may">May 2008</option>
      <option value="jun">June 2008</option>
    
    </select>
    <input type="submit" value="Download" />
    </form>
    <script>
    <script type="text/javascript">
    var base = 'http://www.[removed].com/';
    var ext = '';
    function GoToUrl(id)
    {
      // identify by form id. Helpful if there's more than one form on page
      if (id == 'dlForm') {
        // get value attribute from first select tag
        s1 = document.getElementById('select-1').value;
        
        // get value attribute from second select tag
        s2 = document.getElementById('select-2').value;
        
        // send user to new url (for download)
        // check if it's the webcal one
        if (s1.indexOf(':') != -1) {
        location.href = s1 +"www.[removed].com/"+ s2 + ext;
    //alert(s1 + "www.[removed].com/"+ s2 + ext);
        }
        else {
        location.href = base + s1 +""+ s2 + ext;
    //alert(base + s1 +"www.[removed].com"+ s2 + ext);
        }
      }
      
    }
    </script>
    </body>
    </html>
    Even though I can't say as it isn't working, angelwatt, I don't think you quite understand me, which is my fault - it's hard to explain :p

    Okay, simple terms. I want the RSS feed for february 2008. I've set it up so s1 links (as it should correctly) to the directory of the feed.

    Now, because I've set it up for RSS, how can I download s1 in iCal or outlook (SEPERATE DIR, DIFFERENT FILE,TOO) as the s1 is set to the RSS directory. Probably my misunderstanding..
    Thank you for the support so far, though :eek:
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    OK, this is what URLs are created currently if you're changing s1 and leaving s2 as the default.

    S1 changing / s2 fixed: (links intentionally broken to prevent robots from following)
    • ht:/ww.[removed].com/test/phpicalendar-0.9.5/rss/rss.php?cal=may&rssview=weekrss.php?cal=may&rssview=week
    • web:/ww.[removed].com/rss.php?cal=may&rssview=week
    • ht:/ww.[removed].com/rss.php?cal=may&rssview=week

    So it sounds like these aren't the links you want. Write out how they should look. That'll give me a better idea of how to fix it. Not knowing all of the files involved is part of trouble understanding it. I have some ideas, but just want to make sure.

    * I just looked at the page you provided. There is an error on it. There's 2 opening script tags. That's causing an issue.
     
  9. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #9
    I think it's working! hehe you are the best, i'm going to have a quick run through to make sure, but it seems to be working fine. ]:D:D:D

    Okay, good news bad news.
    Good news is that RSS, iCal and outlook links all work accordingly.
    bad news
    Code:
    <form id="dlForm" onsubmit="GoToUrl(this.id); return false;">
    <select id="select-1">
      <option value="[B]test/phpicalendar-0.9.5/rss/rss.php?cal=may&rssview=week">RSS[/B]</option>
      <option value="[B]webcal://">iCal[/B]</option>
        <option value="">Outlook</option>
    </select>
    <select id="select-2">
      <option value="[B]rss.php?cal=may&rssview=week">February 2008[/B]</option>
      <option value="[B]test/phpicalendar-0.9.5/calendars/may.ics[/B]">March 2008</option>
        <option value="apr">April 2008</option>
      <option value="may">May 2008</option>
      <option value="jun">June 2008</option>
    See, I want to be able to select February iCal but it's asking for RSS. Same with march, any ideas?
    Notice in s1 I've added it all there?
    I'll update this post with the links i need.

    I think i might be confused, but as said before, i can't set the RSS field to the 'may' document because it just pulls that from everything. Like if i put it in March, it would just get the RSS Feed.

    Note: I know it's meant to be march not may :p
    Thanks

    Edit: I think i might be getting confused myself
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    I figured the months were mismatched on purpose so never brought it up.

    I've been thinking about ways to change the HTML portion to be a little more straight forward. Don't copy this over to your current document, it won't work without changing the JavaScript. We could then keep all the URL pieces in the JavaScript and use if and switch type statements to construct the needed URL to download. Though I'll still need to see the needed URLs I mentioned to work out the JavaScript part. This is only an idea, we don't have to go this route.

    HTML:
    <form id="dlForm" onsubmit="GoToUrl(this.id); return false;">
    <select id="format">
      <option value="rss">RSS</option>
      <option value="webcal">iCal</option>
      <option value="outlook">Outlook</option>
    </select>
    <select id="month">
      <option value="feb2008">February 2008</option>
      <option value="mar2008">March 2008</option>
      <option value="apr2008">April 2008</option>
      <option value="may2008">May 2008</option>
      <option value="jun2008">June 2008</option>
    </select>
    </form>
     
  11. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #11
    I guess that would work, but the javascript would have to contain some form of format=rss,month=feb.
    EDIT: When you're free if you don't mind, perhaps add my AIM? Also when it's working i'll post it on here for public use as I've never seen it freely available (there are only paid options).
     
  12. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #12
    I don't use any IM services. Grew out of it.
     
  13. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
    #13
    In the IT Industry, design epecially it's usually considered a business tool, MSN especially..

    Okay, perhaps If i gave you access to the files you can understand my problem? I'm finding it hard to explain, thus giving you the wrong answer. I don't want to waste any more of your time than I already have :eek:

    Thanks angelwatt :)
     
  14. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #14
    Well I'm not in IT, I'm a research scientist. Web design is just a hobby for me most of the time. Occasionally people pay me, but mostly I just do stuff for free because I enjoy it. My work place doesn't allow chat. Using this forum actually rides the line of being allowable.

    I don't really need access to the files, but knowing the paths to them would at least help and the folder structure. I just need to know what the download URLs need to look like so I can come up with a way to create them in JavaScript. You can send me a PM of this information if you don't want to post here. The solution will be pretty easy once I get a grip on the requirements. We're practically there, just a little mismatch on some specifics.
     
  15. EvanLugh thread starter macrumors 68000

    EvanLugh

    Joined:
    Aug 29, 2007
    Location:
    Developer land
  16. edesignuk Moderator emeritus

    edesignuk

    Joined:
    Mar 25, 2002
    Location:
    London, England
Thread Status:
Not open for further replies.

Share This Page