SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy question, forming a URL + GET requests

    Hey,

    I'm pretty new to JS, and I was wanting to write a function which took three arguments, and redirected the user based on the arguments.

    I wrote this:

    Code JavaScript:
    function Booking(time, week, day) {
    	window.location="redirect.php?time=" + time + "&week=" + week + "&day=" + day;
    }

    I'm running it as an onClick, and it doesn't do anything. If I contract it to one argument, it works fine, but I need all three arguments.

    Any ideas what I'm doing wrong? I imagine its pretty simple.

    Thanks,
    Chris

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Nothing seems wrong with the code. How are you calling it?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was wanting to do it to a table cell, but it doesn't work from a <a> either.

    Code HTML4Strict:
    <table width="500" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td onClick="Booking(1, 1, Monday)">This cell </td>
      </tr>
    </table>
    <a onClick="Booking(1, 1, Monday)">Hello</a>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    It fails because you're trying to pass a variable called Monday, which because it doesn't exist is throwing up an error.

    You want instead to pass a string, "Monday"

    Use this instead:

    Code javascript:
    Booking(1, 1, 'Monday');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Addict silentcollision's Avatar
    Join Date
    Jun 2006
    Location
    New Zealand
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome, problem solved.

    Thank you very much!


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
  •